// JavaScript Document
var MIN_WIDTH = 980;
var MIN_HEIGHT = 540;
var MIN_WIDTH_MENU_OPEN = 200;
var MAX_WIDTH_MENU_OPEN = 300;
var MIN_WIDTH_SECTION = MIN_WIDTH-MIN_WIDTH_MENU_OPEN;
var MAX_WIDTH_SECTION = 2600;
var HEIGHT_FOOTER = 25;
var WIDTH_SCROLL_BAR = 5;
var MAX_WIDTH_IMAGE_HEADER_CAT = 270;
var MAX_ELEMENT_SLIDER_PRODOTTI_ELENCO = 4;
var MARGIN_TOP_ELEMENT_GALLERY_PROD = 0;
var HEIGHT_PROD_CORRELATI = 250;
var WIDTH_PROD_CORRELATI = 100;
var WIDTH_ACCESSORI_CONTAINER = 235;
var WIDTH_PAM_LIST_CONTAINER = 197;
var MARGIN_PROD_CORRELATI = 29;
var WIDTH_RIFLESSO_OROLOGI_SLIDER = 1289;
var MARGIN_TAB_PRODOTTO = 30;
var WIDTH_COLUMN_TEXTURE_ACCESSORI = 80;
var NUM_COLUMN_ACCESSORI_TAB = 5;
var MARGIN_COLUMN_ACCESSORI_TAB = 20;
var MARGIN_COLUMN_ACCESSORI_TAB = 20;
var WIDTH_LINK_DETAIL_TAB_ACCESSORI_PAM = 55;
var MAX_SIZE_TITLE_BOUTIQUE = 106;
var MIN_SIZE_TITLE_BOUTIQUE = 90;
var MAX_HEIGHT_IMG_OVER_COVER_COLLECTIONS = 500;
var MARGIN_SLIDER_PRODOTTI = 50;
var FORCE_NO_SLIDER_PRODUCT = false;
var deltaTitle = 3;
var correlatiOpen = false;
var window_width;
var window_height;
var widthMenu;
var heightContentScroller = 0;
var firstLoad = true;
var newheightSectionBlockTemplate;
var widthImgOriginalHeaderCat;
var heightImgOriginalHeaderCat;
var widthContentTemplate;
var widthColumnCoverWhithOverlayer;
var timeOutAutoPlayGalleryprodotti = 5000;
var intervallAutoSlide = "";
var isMobile = navigator.platform.indexOf("iPad") != -1 || navigator.platform.indexOf("iPhone") != -1;

jQuery(document).ready(function(){
	
	window_width = parseInt($(window).width(),10);
	window_height = parseInt($(window).height(),10);
	//setto la dimensione della finestra, quindi del template
	setDimensionWindow();
	
	if(isMobile)
	{
		FORCE_NO_SLIDER_PRODUCT = true;
		$('.content_footer').addClass('mobile');
		$('.bt_minimize_footer_home').addClass('mobile');
	}
		

	if(isMobile && $.browser.version == "533.17.9" && $('.wrap_home').length > 0 || ($.browser.msie  && $.browser.version == "7.0"))
	{
		$('.wrap_text_quote').css({position: 'absolute', top: '50%'})
		
		$('.wrap_text_quote').each(function(){
			var tmpHeight = parseInt($(this).height(),10);
			$(this).css('margin-top',"-"+(tmpHeight/2)+'px')
			
			
		});
	}
	
	if(isMobile || FORCE_NO_SLIDER_PRODUCT)
		MAX_ELEMENT_SLIDER_PRODOTTI_ELENCO = 3;
		
	if($(".wrap_home").length > 0)
	{
		MAX_WIDTH_SECTION = 1315;
		if($.browser.msie && parseInt($.browser.version,10) < 9 )	
		{
			$(".wrap_home").width(790);
		}
	}
	
	setPositionFooter();
	
	if($('.block_page').length > 0 && $('.block_page').eq(0).attr('view') == "calibro")	
	{
		HEIGHT_PROD_CORRELATI = 160;
		//gestisco la grandezza del wrapper dei prodotti correlati rispetto ai calibri
		setWidthContentProdCorrelatiMovements();
	}
	
	if($('.block_page').length > 0 && $('.block_page').eq(0).attr('view') == "accessorio")	
	{
		//gestisco la grandezza delle colonne delle declinazioni accessorio
		setWidthColumnTabDeclinazioneAccessorio();
	}
	
	if($('.block_page').length > 0 && $('.block_page').eq(0).attr('view') == "orologio")	
	{
		//gestisco la grandezza delle colonne delle declinazioni accessorio nel dettaglio del pam
		setWidthColumnTabAccessorioPam();
	}
	
	if($('.block_page').length > 0 && $('.block_page').eq(0).attr('view') == "stores")	
	{
		//gestisco la grandezza del titolo header nel dettaglio delle boutiques
		setDimensionTitleBoutique();
	}
	
	if($('.block_page').length > 0 && $('.block_page').eq(0).attr('view') == "categorylist" && $('.block_page').eq(0).attr('isFull') == "1")	
	{
		//se sono nella vista category list e uso tutto lo schermo aumento la grandezza massima delle immagine di copertina categoria
		MAX_WIDTH_IMAGE_HEADER_CAT = 350;
	}

	if($('.block_page').length > 0 && $('.block_page').eq(0).attr('view') == "categorylistwatch" && $('.block_page').eq(0).attr('isFull') == "1")	
	{
		//se sono nella vista category list e uso tutto lo schermo aumento la grandezza massima delle immagine di copertina categoria
		//MAX_WIDTH_IMAGE_HEADER_CAT = 350;
		MAX_WIDTH_IMAGE_HEADER_CAT = 270;

		if($('.element_header_cat').length == 4)
		{
			numElementRowHeaderCat = 4;
			MAX_WIDTH_IMAGE_HEADER_CAT = 270;
			$('.element_header_cat .img_cat').css({'margin-left':'25px', 'margin-right':'25px'});
		}
		else if($('.element_header_cat').length == 3)
		{
			numElementRowHeaderCat = 3;
			MAX_WIDTH_IMAGE_HEADER_CAT = 410;
			$('.element_header_cat .img_cat').css({'margin-left':'0px', 'margin-right':'0px'});
		}

	}
	
	//gestisco il porizionamento della lista accessori nell'elenco
	if($(".accessori_list").length > 0 && $('.block_page').eq(0).attr('view') != "timeline")
	{
		if($(".accessori_list").hasClass('fibbie_list'))
			WIDTH_ACCESSORI_CONTAINER = 290;
			
		setPositionListAccessori();
	}
	
	if($('.block_page').length > 0 && $('.block_page').eq(0).attr('view') == "stores")	
	{
		//gestisco la grandezza del titolo header nel dettaglio delle boutiques
		
		if(parseInt($('#big_title_store').css('height')) > 125 && widthContentTemplate < (MIN_WIDTH_SECTION + widthMenu))
		{
			$("#big_title_store").css('font-size',90+'px');
		}
		setDimensionTitleBoutique();
	}
	if($('.block_page').length > 0 && $('.block_page').eq(0).attr('view') == "orologio")	
	{	
		//posiziono i banner nel dettaglio del prodotto
		setPositionBannerProducts();
	}
	
	
	//attacco il click sul more information delle fibbie
	$('.bt_more_fibbia_desc').on('click',function(){
		var obj = $(this);
		openDescFibbia(obj);
	});
	
	$('.fibbie_list li').on('click',function(){
		var obj = $(this).find('.bt_more_fibbia_desc');
		openDescFibbia(obj);
	});
	
	//gestrisco il posizionamento del titolo about panerai solo su ie7
	if($('.wrap_text_header_mod').length>0 && $.browser.msie  && $.browser.version == "7.0")
	{
		var heightText = parseInt($('.wrap_text_header').height(),10);
		$('.wrap_text_header_mod').css('margin-top','-'+(heightText/2)+'px');
	}
	
	$('.bt_luminova').click(function(){
		if($(this).hasClass('active'))
		{
			
			$(this).html(Joomla.JText._('TPL_PANERAI_NIGHT_VIEW'));
			$(this).removeClass('active');
			$(this).parents('li').find('.luminova_container').fadeOut();
			
			/*
			$(this).html(Joomla.JText._('TPL_PANERAI_NIGHT_VIEW'));
			$(this).removeClass('active');
			var obj = $(this).parents('li');
			$(this).parents('li').find('.item_slider_prod_gallery').fadeIn(function(){
			
				obj.find('.luminova_container').fadeOut();	
				
			});
			*/
			
		}
		else
		{
			
			$(this).html(Joomla.JText._('TPL_PANERAI_DAY_VIEW'));
			$(this).addClass('active');
			$(this).parents('li').find('.luminova_container').fadeIn();
			/*
			
			$(this).html(Joomla.JText._('TPL_PANERAI_DAY_VIEW'));
			$(this).addClass('active');
			var obj = $(this).parents('li');
			$(this).parents('li').find('.item_slider_prod_gallery').fadeOut(function(){
			
				obj.find('.luminova_container').fadeIn();	
				
			});
			
			*/
			
			
			
		}
	});
	
	
	setPositionBtFindPanerai();
	
	$(window).bind('orientationchange',function(){
		window_width = parseInt($(window).width(),10);
		window_height = parseInt($(window).height(),10);
		//setto la dimensione della finestra, quindi del template
		setDimensionWindow();
	});
	
});

jQuery(window).resize(function(){
	
	window_width = parseInt($(window).width(),10);
	window_height = parseInt($(window).height(),10);
	setDimensionWindow();
	
	if($('.block_page').length > 0 && $('.block_page').eq(0).attr('view') == "calibro")	
	{
		HEIGHT_PROD_CORRELATI = 160;
		//gestisco la grandezza del wrapper dei prodotti correlati rispetto ai calibri
		setWidthContentProdCorrelatiMovements();
	}
	
	if($('.block_page').length > 0 && $('.block_page').eq(0).attr('view') == "accessorio")	
	{
		//gestisco la grandezza delle colonne delle declinazioni accessorio
		setWidthColumnTabDeclinazioneAccessorio();
	}
	
	if($('.block_page').length > 0 && $('.block_page').eq(0).attr('view') == "orologio")	
	{
		//gestisco la grandezza delle colonne delle declinazioni accessorio nel dettaglio del pam
		setWidthColumnTabAccessorioPam();
	}
	
	if($('.block_page').length > 0 && $('.block_page').eq(0).attr('view') == "stores")	
	{
		//gestisco la grandezza del titolo header nel dettaglio delle boutiques
		setDimensionTitleBoutique();
	}
	
	//gestisco il porizionamento della lista accessori nell'elenco
	if($(".accessori_list").length > 0 && $('.block_page').eq(0).attr('view') != "timeline")
	{
		if($(".accessori_list").hasClass('fibbie_list'))
			WIDTH_ACCESSORI_CONTAINER = 290;
		
		setPositionListAccessori();
	}
	
	if($('.block_page').length > 0 && $('.block_page').eq(0).attr('view') == "orologio")	
	{	
		//posiziono i banner nel dettaglio del prodotto
		setPositionBannerProducts();
	}
	
	//gestrisco il posizionamento del titolo about panerai solo su ie7
	if($('.wrap_text_header_mod').length>0 && $.browser.msie  && $.browser.version == "7.0")
	{
		var heightText = parseInt($('.wrap_text_header').height(),10);
		$('.wrap_text_header_mod').css('margin-top','-'+(heightText/2)+'px');
	}
	
	
	loadMore('wrap_load_more',true);
	
	setPositionListPam();
	
	setPositionBtFindPanerai();
	
});

function setPositionBtFindPanerai()
{
	$(".bt_find_my_panerai").css('visibility','hidden');
	var rightBtPanerai = window_width - widthMenu - widthContentTemplate + 100 + 3;
	//alert($(".mod-languages").width())
	if($(".bt_find_my_panerai").css('position') == 'absolute')
		rightBtPanerai = parseInt($(".mod-languages").width(),10) + 30;
		
	$(".bt_find_my_panerai").css('right',rightBtPanerai+'px');
	
	$(".mod-languages").find('.jNiceSelectWrapper').width(parseInt($(".mod-languages").width(),10));
	$(".mod-languages").find('.jNiceSelectText').width(parseInt($(".mod-languages").width(),10)-20);
	$(".bt_find_my_panerai").css('visibility','visible');
	$(".mod-languages").css('visibility','visible');
	
}

function setDimensionWindow()
{	
	$('body').css('overflow','hidden');
	
	if(window_height < MIN_HEIGHT)
		$(".total_wrap_page").height(MIN_HEIGHT+"px");
	else
		$(".total_wrap_page").height(window_height+"px");
		
	if(window_width < MIN_WIDTH)
		$(".total_wrap_page").width(MIN_WIDTH+"px");
	else
		$(".total_wrap_page").width(window_width+"px");
	
	if(window_height < MIN_HEIGHT || window_width < MIN_WIDTH)
		$('body').css('overflow','auto');
	//dopo aver settato le dimensioni della pagina setto le dimensioni del menu
	setDimensionMenu();
	
	//Aggiusto la posizione del footer
    setPositionFooter();
}

function setDimensionMenu()
{
	if(window_height < MIN_HEIGHT)
		$(".sup_wrap_menu").height(MIN_HEIGHT+"px");
	else
		$(".sup_wrap_menu").height((window_height-HEIGHT_FOOTER)+"px");
	
	newWidthMenu = Math.floor((MIN_WIDTH_MENU_OPEN*window_width)/MIN_WIDTH);
	
	if(newWidthMenu > MAX_WIDTH_MENU_OPEN)
	{
		$(".sup_wrap_menu").width(MAX_WIDTH_MENU_OPEN+"px");
		widthMenu = MAX_WIDTH_MENU_OPEN;
	}
	else if(newWidthMenu < MIN_WIDTH_MENU_OPEN)
	{
		$(".sup_wrap_menu").width(MIN_WIDTH_MENU_OPEN+"px");
		widthMenu = MIN_WIDTH_MENU_OPEN;
	}
	else
	{
		$(".sup_wrap_menu").width(newWidthMenu+"px");
		widthMenu = newWidthMenu;
	}
		
	setDimensionSectionTemplate();	
}

function setDimensionSectionTemplate()
{
	var newWidthSectionTemplate = parseInt($(".total_wrap_page").width(),10)-widthMenu;
	var newheightSectionTemplate = parseInt($(".total_wrap_page").height(),10)-HEIGHT_FOOTER;
	
	$("#section_template").width(newWidthSectionTemplate+"px");
	$("#section_template").height(newheightSectionTemplate+"px");
	
	setDimensionContentTemplate();
}

function setDimensionContentTemplate()
{
	if(parseInt($("#section_template").width(),10) > MAX_WIDTH_SECTION)
	{
		$(".content_scroller_element").width((MAX_WIDTH_SECTION)+"px");
		widthContentTemplate = MAX_WIDTH_SECTION;
	}
	else if(parseInt($("#section_template").width(),10) < MIN_WIDTH_SECTION)
	{
		$(".content_scroller_element").width((MIN_WIDTH_SECTION)+"px");
		widthContentTemplate = MIN_WIDTH_SECTION;
	}
	else
	{
		$(".content_scroller_element").width(parseInt($("#section_template").width(),10)+"px");
		widthContentTemplate = parseInt($("#section_template").width(),10);
	}
	
	if($(".block_page").length > 0)
	{
		setDimensionBlockTemplate();
	}
	else
	{
		setScroller();
		if(isMobile)
			$('.block_loader_site').css('display','none');
		else
			$('.block_loader_site').fadeOut();
	}
}



//setto la dimensione dei blocchi template del sito
function setDimensionBlockTemplate()
{
	//newheightSectionBlockTemplate = parseInt($(".total_wrap_page").height(),10)-HEIGHT_FOOTER;
	if($(".block_page").length > 0 && $('.block_page').eq(0).attr('view') == "categorylist")
		newheightSectionBlockTemplate = Math.floor((widthContentTemplate*9)/16)+100;
	else
		newheightSectionBlockTemplate = Math.floor((widthContentTemplate*9)/16);
	
	if(newheightSectionBlockTemplate > 720)
		newheightSectionBlockTemplate = 720;
	if(newheightSectionBlockTemplate < MIN_HEIGHT-HEIGHT_FOOTER)
		newheightSectionBlockTemplate = MIN_HEIGHT-HEIGHT_FOOTER;
	
	if($('.block_page').eq(0).attr('view') != "categorylistwatch")
		$(".block_page").css('height',newheightSectionBlockTemplate+'px');
	
	if($(".sup_wrap_header_text").length > 0)
		$(".sup_wrap_header_text").height(newheightSectionBlockTemplate);
	
	var setLoadBkg = false;
	
	$(".block_page").each(function(){
		
		//gestisco un immagine di sfondo a tutta pagina
		if($(this).find('.bg_page').length > 0)
		{
			$(this).find('.img_appoggio_bg_page').load(function(){
				
				var widthImgOriginal = parseInt($(this).width(),10);
				var heightImgOriginal = parseInt($(this).height(),10);
				
				var newWidth =  widthContentTemplate;
				var newHeight =  (heightImgOriginal*widthContentTemplate)/widthImgOriginal;
				
				if(newHeight < window_height)
				{
					var newHeight =  window_height;
					var newWidth =  (widthImgOriginal*window_height)/heightImgOriginal;
				}
				
				if($(this).parents('.bg_page').attr("forceWidth") == "true")
				{
					var newWidth =  widthContentTemplate;
					var newHeight =  (heightImgOriginal*window_height)/widthImgOriginal;
					
					if(newHeight < heightContentScroller)
					{
						$(this).parents('.block_page').find('.img_bg_page').css('top','50%');
						$(this).parents('.block_page').find('.img_bg_page').css('margin-top','-'+(((heightContentScroller-newHeight)/2)+140)+'px');
					}	
				}
				
				$(this).parents('.block_page').find('.img_bg_page').attr('src',$(this).attr('src')).width(newWidth).height(newHeight).hide().css('visibility','visible').fadeIn();
				
			});
			
			$(this).find('.img_appoggio_bg_page').attr('src',$(this).find('.bg_page').attr('bgImage'));
		}
		
		//ho una gallery in pagina che deve seguire la logica dei blocchi del sito
		if($(this).find('.cnt_slider_prodotti_gallery').length > 0)
		{
			//sono nella pagina di dettaglio prodotto
			$(this).find('.cnt_slider_prodotti_gallery').width(widthContentTemplate).height(newheightSectionBlockTemplate);
			$(this).find('.cnt_slider_prodotti_gallery').find('ul').width(widthContentTemplate).height(newheightSectionBlockTemplate);
			
			//gestisco la dimensione del wrapper dei prodotti correlati
			var numCorrelati = parseInt($('.sub_wrap_correlati ul').find('li').length,10);
			var elementRiga = Math.floor(widthContentTemplate/(WIDTH_PROD_CORRELATI+(MARGIN_PROD_CORRELATI*2)));
			if(elementRiga>numCorrelati)
				elementRiga = numCorrelati;	
			
			var righe = Math.ceil(numCorrelati/elementRiga);
			
			$('.sub_wrap_correlati ul').width(Math.abs(parseInt(elementRiga,10))*(WIDTH_PROD_CORRELATI+(MARGIN_PROD_CORRELATI*2)));
			
			if(correlatiOpen)
			{
				//alert(righe + '*' + HEIGHT_PROD_CORRELATI)
				$('.wrap_prod_correlati').height(righe*HEIGHT_PROD_CORRELATI);
			}
		}
		
		//se il blocco pagina deve occupare tutta la genadezza dello schermo
		if(parseInt($(this).attr('isFull')) == 1 && parseInt($(this).attr('isFull')) == 1)
		{
			newheightSectionBlockTemplate = window_height-HEIGHT_FOOTER;
			if(newheightSectionBlockTemplate < MIN_HEIGHT-HEIGHT_FOOTER)
				newheightSectionBlockTemplate = MIN_HEIGHT-HEIGHT_FOOTER;
				
			$(".block_page").css('height',(newheightSectionBlockTemplate)+'px');
			
			if((isMobile || FORCE_NO_SLIDER_PRODUCT) && $(this).attr('view') == 'orologilist')
			{	

				$(".block_page .cnt_slider_prodotti_list").css('text-align','left');
				$(".arrow_sx, .arrow_dx").hide();
				
				var a = parseInt($('.cnt_slider_prodotti_list').find('li').height(),10);
				
				if(!firstLoad)
				{
					var obj = $(".block_page").find('.cnt_slider_prodotti_list').find('ul').find('li:first').find(".img_appoggio_load_slider_prod");
					var nElementSliderProdotti = parseInt($(".block_page").find('.cnt_slider_prodotti_list').find('ul').find('li').length,10);
					var newWidthElementSliderProdottiElenco = (widthContentTemplate/MAX_ELEMENT_SLIDER_PRODOTTI_ELENCO);
					
					var widthOriginalImg = 	parseInt(obj.width(),10);
					var heightOriginalImg = parseInt(obj.height(),10);
					
					var marginImageSlider = parseInt(obj.parents('li').find('.item_slider_prod').css('margin-left'),10)+parseInt(obj.parents('li').find('.item_slider_prod').css('margin-right'),10);
					
					var newWidthImageSliderProdotti = newWidthElementSliderProdottiElenco-marginImageSlider;
					var newHeightImage = Math.floor((newWidthImageSliderProdotti*heightOriginalImg)/widthOriginalImg);
					
					var maxHeightDescription = parseInt(obj.parents('li').find('p').height(),10);
					
					obj.parents('li').parents('ul').find('li').each(function(){
						if(maxHeightDescription < parseInt($(this).find('p').height(),10))
							maxHeightDescription = parseInt($(this).find('p').height(),10);		
					});
					
					var ingombroTitolo = parseInt(obj.parents('.bkg_first_block').find('h1').height(),10)+parseInt(obj.parents('.bkg_first_block').find('h1').css('margin-top'),10)+parseInt(obj.parents('.bkg_first_block').find('h1').css('padding-top'),10)+parseInt(obj.parents('.bkg_first_block').find('h1').css('padding-bottom'),10)+parseInt(obj.parents('.bkg_first_block').find('h1').css('margin-bottom'),10);
					var ingombroSubTitolo = parseInt(obj.parents('.bkg_first_block').find('h2').height(),10)+parseInt(obj.parents('.bkg_first_block').find('h2').css('margin-top'),10)+parseInt(obj.parents('.bkg_first_block').find('h2').css('padding-top'),10)+parseInt(obj.parents('.bkg_first_block').find('h2').css('padding-bottom'),10)+parseInt(obj.parents('.bkg_first_block').find('h2').css('margin-bottom'),10);
							
					var marginTopWrapSlider = (((newheightSectionBlockTemplate-ingombroTitolo-ingombroSubTitolo) - (newHeightImage+maxHeightDescription))/2) - ((ingombroTitolo-ingombroSubTitolo)*0.5);			
					
					if(marginTopWrapSlider < 10)
						marginTopWrapSlider = 10;
					
					if(isMobile || FORCE_NO_SLIDER_PRODUCT)
					{
						marginTopWrapSlider = 0;
						var row = Math.ceil((nElementSliderProdotti/MAX_ELEMENT_SLIDER_PRODOTTI_ELENCO));
						var heightWrapSlider = newHeightImage*row;
					}
					
					if(obj.parents('li').find('.loader').css('display') == 'none')
					{
						//alert('loader display none')
						if(!isMobile && !FORCE_NO_SLIDER_PRODUCT)
						{
							obj.parents('li').width(newWidthElementSliderProdottiElenco).height(newHeightImage+maxHeightDescription);
							obj.parents('li').parents('ul').width(newWidthElementSliderProdottiElenco*nElementSliderProdotti).height(newHeightImage+maxHeightDescription);
							obj.parents('li').parents('ul').parent().height(newHeightImage+maxHeightDescription).css('margin-top',marginTopWrapSlider+"px");
							//obj.parents('li').parents('ul').css('margin-top',marginTopWrapSlider+"px");
							obj.parents('li').find('.item_slider_prod').width(newWidthImageSliderProdotti).height(newHeightImage);
						}else
						{
							obj.parents('ul').find('li').width(newWidthElementSliderProdottiElenco).height(newHeightImage+(maxHeightDescription*2));
							
							obj.parents('ul').width(widthContentTemplate).height(heightWrapSlider);
							
							obj.parents('li').parents('ul').css('margin-top',marginTopWrapSlider+"px");
							obj.parents('li').find('.item_slider_prod').width(newWidthImageSliderProdotti).height(newHeightImage);
							
							$('.cnt_slider_prodotti_list').height(heightWrapSlider+((maxHeightDescription*2)*row));
							$('.cnt_slider_prodotti_list').find('ul').width(widthContentTemplate).height(heightWrapSlider+((maxHeightDescription*2)*row));
							$('.cnt_slider_prodotti_list').parent().height(heightWrapSlider+ingombroTitolo+ingombroSubTitolo+((maxHeightDescription*2)*row));
							$('.cnt_slider_prodotti_list').find('ul').parents('.block_page').height(heightWrapSlider+ingombroTitolo+ingombroSubTitolo+((maxHeightDescription*2)*row));
							
							setScroller();
						}
					}
					else
					{
						//alert('loader display inline')
						obj.parents('li').find('.loader').fadeOut(function(){	
						
							if(!isMobile && !FORCE_NO_SLIDER_PRODUCT)
							{
								//alert('not mobile')
								//alert(obj.parents('li').find('.item_slider_prod').length);
								//obj.parents('li').find('.item_slider_prod').attr('src',obj.parents('li').attr('img'));
								obj.parents('li').find('.item_slider_prod').width(newWidthImageSliderProdotti).height(newHeightImage);
								obj.parents('li').find('.item_slider_prod').fadeIn();
								obj.parents('li').find('p').hide().css('visibility','visible').fadeIn();
								
								obj.parents('li').parents('ul').height(newHeightImage+maxHeightDescription);
								obj.parents('li').parents('ul').parent().height(newHeightImage+maxHeightDescription).css('margin-top',marginTopWrapSlider+"px");;
								obj.parents('li').height(newHeightImage+maxHeightDescription);
								
								obj.parents('li').parents('ul').parent().find('.arrow_sx, .arrow_dx').css('visibility','visible');
								
								//obj.parents('li').parents('ul').css('margin-top',marginTopWrapSlider+"px");			
							}
							else
							{
								//obj.parents('li').find('.item_slider_prod').attr('src',obj.parents('li').attr('img'));
								obj.parents('li').find('.item_slider_prod').width(newWidthImageSliderProdotti).height(newHeightImage);
								obj.parents('li').find('.item_slider_prod').fadeIn();
								obj.parents('li').find('p').hide().css('visibility','visible').fadeIn();
								
								obj.parents('li').parents('ul').css('margin-top',marginTopWrapSlider+"px");
								
								obj.parents('li').width(newWidthElementSliderProdottiElenco).height(newHeightImage+maxHeightDescription*2);
								
								obj.parents('li').parents('ul').width(widthContentTemplate).height(heightWrapSlider+((maxHeightDescription*2)*row));
								obj.parents('li').parents('ul').parent().height(heightWrapSlider+ingombroTitolo+ingombroSubTitolo+((maxHeightDescription*2)*row));
								obj.parents('li').parents('ul').parents('.block_page').height(heightWrapSlider+ingombroTitolo+ingombroSubTitolo+((maxHeightDescription*2)*row));	
												
								setScroller();
							}
							
						});	
					}
					
				}
				//setDimensionImageSliderProduct($(".block_page").find('.cnt_slider_prodotti_list').find('ul').find('li:first').find(".img_appoggio_load_slider_prod"));
				
				
				//$(".block_page").css('height',(newHeightElementSliderProdottiElenco*(Math.round(nElementSliderProdotti/MAX_ELEMENT_SLIDER_PRODOTTI_ELENCO)))+'px');
				
				/*
				var nElementSliderProdotti = parseInt($(this).find('.cnt_slider_prodotti_list').find('ul').find('li').length,10);
				var ingombroTitolo = parseInt($(this).find('h1').height(),10)+parseInt($(this).find('h1').css('margin-top'),10)+parseInt($(this).find('h1').css('padding-top'),10)+parseInt($(this).find('h1').css('padding-bottom'),10)+parseInt($(this).find('h1').css('margin-bottom'),10);
				var ingombroSubTitolo = parseInt($(this).find('h2').height(),10)+parseInt($(this).find('h2').css('margin-top'),10)+parseInt($(this).find('h2').css('padding-top'),10)+parseInt($(this).find('h2').css('padding-bottom'),10)+parseInt($(this).find('h2').css('margin-bottom'),10);
				
				var newHeightElementSliderProdottiElenco = newheightSectionBlockTemplate-ingombroTitolo-ingombroSubTitolo;
				var newWidthElementSliderProdottiElenco = (widthContentTemplate/MAX_ELEMENT_SLIDER_PRODOTTI_ELENCO);
				$(this).find('.cnt_slider_prodotti_list').find('ul').width(widthContentTemplate).height(newHeightElementSliderProdottiElenco*(Math.round(nElementSliderProdotti/MAX_ELEMENT_SLIDER_PRODOTTI_ELENCO)));
				
				$(".block_page").css('height',(newHeightElementSliderProdottiElenco*(Math.round(nElementSliderProdotti/MAX_ELEMENT_SLIDER_PRODOTTI_ELENCO)))+'px');
				*/
				
			}
		}
		
		//gestisco le cover copertine con 2 colonne
		if(parseInt($(this).attr('haveHover'),10) == 1)
		{
			widthColumnCoverWhithOverlayer = Math.floor(widthContentTemplate/2);
			$('.wrap_image_hover_bkg_cover_cat').width(widthColumnCoverWhithOverlayer).height(newheightSectionBlockTemplate);
			$('.sup_wrap_txt_cover_category').width(widthColumnCoverWhithOverlayer).height(newheightSectionBlockTemplate).css({left: widthColumnCoverWhithOverlayer+'px'});
		}
		
		//se i blocchi hanno un bkg attacco la load sull'immagine appoggio
		if(firstLoad)
		{
			//se ho una gallery dei prodotti attacco la load sulle immagini
			if($(this).find('.cnt_slider_prodotti_gallery').length > 0)
			{
				if($(this).find('.cnt_slider_prodotti_gallery').attr('autoplay') != undefined && $(this).find('.cnt_slider_prodotti_gallery').attr('autoplay') != '1')
				{	
					intervallAutoSlide = setInterval('goGalleryProdottiByCursor("autoplay")',timeOutAutoPlayGalleryprodotti);
				}
				
				$('.cnt_slider_prodotti_gallery').find('ul').find('li').find('.appoggio_gallery_prodotti').on('load',function(){
					setDimensionGalleryProdotti();			
				});
				
				$('.cnt_slider_prodotti_gallery').find('ul').find('li.active').find('.appoggio_gallery_prodotti').attr('src',$('.cnt_slider_prodotti_gallery').find('ul').find('li.active').attr('img'));
				
			}
			
			//sono nella sezione di elenco prodotti con lo slider
			if($(this).find('.cnt_slider_prodotti_list').length > 0)
			{
				setDimensionElementSliderFullScreen($(this));
			}
			
			//il blocco pagina ha uno sfondo
			if($(this).attr('bkg') != undefined || $(this).attr('bkg') == "")
			{
				
				if(!setLoadBkg)
				{
					//setto la load sull'immagine di sfondo del blocco pagina
					$('.img_appoggio_bkg_block_page').load(function(){
						setDimensionBkgBlock($(this).parent());			
					});
					//se ha un overlayer metto la load anche qui e setto le dimensioni dell'hover
					if(parseInt($(this).attr('haveHover'),10) == 1)
					{
						$('.img_appoggio_over_bkg_block_page').load(function(){
							setDimensionOverBkgBlock($(this).parent().parent());
						});
					}
					setLoadBkg = true;
				}
				
				$(this).find('.img_appoggio_bkg_block_page').attr('src',$(this).attr('bkg'));
				
				//se ho anche l'immagine di hover sul bkg della copertina categoria
				if(parseInt($(this).attr('haveHover'),10) == 1)
					$(this).find('.img_appoggio_over_bkg_block_page').attr('src',$(this).attr('overBkg'));
			}
			
		}
		else
		{
			//se ho già caricato i bkg delle sezioni risetto le dimensioni
			if($(this).find('.img_appoggio_bkg_block_page').length > 0 )
			setDimensionBkgBlock($(this));
			
			if(parseInt($(this).attr('haveHover'),10) == 1)
				setDimensionOverBkgBlock($(this));
			
			if($(this).find('.cnt_slider_prodotti_list').length > 0)
				setDimensionImageSliderProduct($(".block_page").find('.cnt_slider_prodotti_list').find('ul').find('li').find(".img_appoggio_load_slider_prod"));	
			
			if($(this).find('.cnt_slider_prodotti_gallery').length > 0 && $(".play_manifattura").css('display') != 'none')
			{
				setDimensionGalleryProdotti();
			}
			
		}
	});
	
	//controllo se in pagina esiste l'header caregorie
	if($('.sub_container_element_header_cat_watch').length > 0)
	{
		var numElementRowHeaderCat;
		if($('.element_header_cat').length == 4)
		{
			numElementRowHeaderCat = 4;
			MAX_WIDTH_IMAGE_HEADER_CAT = 270;
			$('.element_header_cat .img_cat').css({'margin-left':'25px', 'margin-right':'25px'});
		}
		else if($('.element_header_cat').length == 3)
		{
			numElementRowHeaderCat = 3;
			MAX_WIDTH_IMAGE_HEADER_CAT = 410;
			$('.element_header_cat .img_cat').css({'margin-left':'0px', 'margin-right':'0px'});
		}
		$('.sub_container_element_header_cat_watch').attr('num_element_for_row', numElementRowHeaderCat);

		var marginImage = parseInt($('.element_header_cat .img_cat').css('margin-left'),10) + parseInt($('.element_header_cat .img_cat').css('margin-right'),10);

		var maxWidthContainerImage = MAX_WIDTH_IMAGE_HEADER_CAT + marginImage;	
		
		var widthContainerHeaderCat = parseInt($('.sub_container_element_header_cat_watch').width(),10);
		var ingombroTitoloHeaderCat = parseInt($('.bkg_first_block h1').height(),10)+parseInt($('.bkg_first_block h1').css('margin-top'),10)+parseInt($('.bkg_first_block h1').css('padding-top'),10)+parseInt($('.bkg_first_block h1').css('padding-bottom'),10)+parseInt($('.bkg_first_block h1').css('margin-bottom'),10);
		
		var marginSubContainerElementHeaderCat = parseInt($('.sub_container_element_header_cat').css('margin-top'),10);
		if(isNaN(marginSubContainerElementHeaderCat))
			marginSubContainerElementHeaderCat = 0;

		var maxWidthContentCatWatch = numElementRowHeaderCat * maxWidthContainerImage;//parseInt($('.sub_container_element_header_cat_watch').width(),10);
		var widthWrapElementsHeaderCat;
		var widthColumnHeaderCat;
		

		widthWrapElementsHeaderCat = widthContainerHeaderCat - marginImage;
		
		if(firstLoad)
		{
			bindLoadElementHeader();
		}
		else if(widthContainerHeaderCat >= maxWidthContentCatWatch)
		{	
			$('.wrap_elements_header_cat').width(maxWidthContentCatWatch);
			$('.img_cat').width(MAX_WIDTH_IMAGE_HEADER_CAT).height('auto');
			$('.element_header_cat').width(maxWidthContainerImage);
		}
		else
		{
			
			widthColumnHeaderCat = parseInt($('.link_img_cat').width(), 10);
			
			var marginDiference = (160 - (widthContainerHeaderCat - (widthColumnHeaderCat * numElementRowHeaderCat)))
			widthWrapElementsHeaderCat = (widthColumnHeaderCat * numElementRowHeaderCat) + marginDiference;
		
			/*if(marginDiference < 0)
				widthWrapElementsHeaderCat = widthColumnHeaderCat * numElementRowHeaderCat;
			if(widthWrapElementsHeaderCat > widthContainerHeaderCat)
				widthWrapElementsHeaderCat = widthContainerHeaderCat;
			*/
			widthWrapElementsHeaderCat = widthContainerHeaderCat;

			widthColumnHeaderCat = widthWrapElementsHeaderCat /numElementRowHeaderCat;
 			//console.log('widthWrapElementsHeaderCat = '+widthWrapElementsHeaderCat+' - widthColumnHeaderCat = '+widthColumnHeaderCat);
			$('.wrap_elements_header_cat').width(widthWrapElementsHeaderCat);
			$('.element_header_cat').width(widthColumnHeaderCat);
			var widthImage = widthColumnHeaderCat - marginImage;
			$('.element_header_cat .img_cat').width(widthImage).height('auto');

			if($('.block_page').length > 0 && $('.block_page').eq(0).attr('view') == "categorylistwatch")
			{
				var heightEl = 0;
				$('.element_header_cat').$.each(function() {
					 
					 if($(this).height() > heightEl)
					 	heightEl = $(this).height();

				});

			var marginTopCover = (window_height - heightEl)/2;
			var heightTitle = $(".block_page h1").height();
			$('.wrap_elements_header_cat').css('margin-top',(marginTopCover-heightTitle-65-20)+"px");

			}



		}
		
	}	

	if($('.sub_container_element_header_cat').length > 0)
	{
		var numElementHeaderCat = parseInt($('.sub_container_element_header_cat').attr('numElementHeaderCat'),10);
		var widthContainerHeaderCat = parseInt($('.sub_container_element_header_cat').width(),10);
		var widthColumnHeaderCat = Math.floor(widthContainerHeaderCat/numElementHeaderCat);
		var ingombroTitoloHeaderCat = parseInt($('.bkg_first_block h1').height(),10)+parseInt($('.bkg_first_block h1').css('margin-top'),10)+parseInt($('.bkg_first_block h1').css('padding-top'),10)+parseInt($('.bkg_first_block h1').css('padding-bottom'),10)+parseInt($('.bkg_first_block h1').css('margin-bottom'),10);
		$('.element_header_cat').width(widthColumnHeaderCat-5);
		//alert('element_header_cat:' + (widthColumnHeaderCat-5))

		var marginSubContainerElementHeaderCat = parseInt($('.sub_container_element_header_cat').css('margin-top'),10);
		if(isNaN(marginSubContainerElementHeaderCat))
			marginSubContainerElementHeaderCat = 0;
		
		$('.element_header_cat').height(newheightSectionBlockTemplate-ingombroTitoloHeaderCat-HEIGHT_FOOTER-marginSubContainerElementHeaderCat);

		//se è la prima volta che carico il sito attacco gli eventi di load sulle immagini dell'header, altrimenti le ridimensiono
		if(firstLoad)
			bindLoadElementHeader();
		else
			setDimensionImageHeaderCat();
	}
	
	//if($(".block_page").length == 0 || parseInt($(".block_page").attr("isFull"),10) == 0 || $(".block_page").attr("isFull") == undefined)
		setScroller();
	
	firstLoad = false;
	
	
	if(isMobile)
		$('.block_loader_site').css('display','none');
	else
		$('.block_loader_site').fadeOut();
	
	
}

function bindLoadElementHeader()
{
	if($(".element_header_cat").length>0)
	{
		$(".element_header_cat").each(function(){
			$(this).find('.img_appoggio_header_cat').attr('src',$(this).attr('imgCat'));
		});
	}
	
	//if(obj == undefined || obj == "")
	//{	
	$(".img_appoggio_header_cat").load(function(){
		setDimensionImageHeaderCat($(this));
	});
	//}
	//else
	//{
	//	$(".img_appoggio_header_cat").load(function(){
	//		var widthContainerImg = obj.width();
	//		$(".img_appoggio_header_cat").width(widthContainerImg);
	//		setDimensionImageHeaderCat($(this));
	//	});
	//}
	
	//attacco l'hover sulle immagini delle categorie
	$(".element_header_cat").mouseover(function(){
		$(this).find('.title_cat_header').addClass('hover');
	});
	
	$(".element_header_cat").mouseout(function(){
		$(this).find('.title_cat_header').removeClass('hover');
	});
	
}

function setDimensionImageHeaderCat(obj)
{
	var ingombroTitoloHeaderCat = parseInt($('.bkg_first_block h1').height(),10)+parseInt($('.bkg_first_block h1').css('margin-top'),10)+parseInt($('.bkg_first_block h1').css('padding-top'),10)+parseInt($('.bkg_first_block h1').css('padding-bottom'),10)+parseInt($('.bkg_first_block h1').css('margin-bottom'),10);
	//alert(parseInt($('.bkg_first_block h1').height(),10) + " " + parseInt($('.bkg_first_block h1').css('margin-top'),10) + " " + parseInt($('.bkg_first_block h1').css('padding-top'),10) + " " + parseInt($('.bkg_first_block h1').css('padding-bottom'),10) + " " + parseInt($('.bkg_first_block h1').css('margin-bottom'),10))
	var marginImage = parseInt($('.element_header_cat .img_cat').css('margin-left'),10) + parseInt($('.element_header_cat .img_cat').css('margin-right'),10);	
	var widthColumn = parseInt($('.element_header_cat').width(),10)-marginImage;
	
	//se la colonna suoera la width massima forzo la larghezza della colonna e dell'immagine
	if(widthColumn > MAX_WIDTH_IMAGE_HEADER_CAT)
	{
		widthColumn = MAX_WIDTH_IMAGE_HEADER_CAT;
		$('.element_header_cat').width(widthColumn+marginImage);
	}	
		
	if(obj == undefined || obj == "")
	{	
		//alert(navigator.userAgent)
		var newHeightImage = Math.floor((widthColumn*heightImgOriginalHeaderCat)/widthImgOriginalHeaderCat);
		
		var newMarginContainerHeaderCat = ((newheightSectionBlockTemplate-ingombroTitoloHeaderCat)-newHeightImage)/2;
		if(newMarginContainerHeaderCat < parseInt($('.bkg_first_block h1').css('margin-bottom'),10))
			newMarginContainerHeaderCat = 0;
		
		var newWidthImage = widthColumn;
		if(newHeightImage > ((newheightSectionBlockTemplate-ingombroTitoloHeaderCat)-parseInt($('.title_cat_header').height(),10)) )
		{
			newHeightImage = ((newheightSectionBlockTemplate-ingombroTitoloHeaderCat)-parseInt($('.title_cat_header').height(),10));
			newWidthImage = (widthImgOriginalHeaderCat*newHeightImage)/heightImgOriginalHeaderCat;
		}
		
		$('.sub_container_element_header_cat').css('margin-top',(newMarginContainerHeaderCat)+'px')
		$('.title_cat_header').hide().css('visible','visible').fadeIn();
		$('.img_cat').width(newWidthImage).height(newHeightImage);
	}
	else
	{
		widthImgOriginalHeaderCat = parseInt(obj.width(),10);
		heightImgOriginalHeaderCat = parseInt(obj.height(),10);
			
		var newHeightImage = Math.floor((widthColumn*heightImgOriginalHeaderCat)/widthImgOriginalHeaderCat);
		var newWidthImage = widthColumn;

		if(newHeightImage > ((newheightSectionBlockTemplate-ingombroTitoloHeaderCat)-parseInt($('.title_cat_header').height(),10)))
		{
			newHeightImage = ((newheightSectionBlockTemplate-ingombroTitoloHeaderCat)-parseInt($('.title_cat_header').height(),10));
			newWidthImage = (widthImgOriginalHeaderCat*newHeightImage)/heightImgOriginalHeaderCat;
		}
		
		obj.parents('.element_header_cat').find('.img_cat').attr('src',obj.attr('src'));
		
		obj.parents('.element_header_cat').find('.loader_oro_cat').fadeOut(function(){
			
			var newMarginContainerHeaderCat = ((newheightSectionBlockTemplate-ingombroTitoloHeaderCat)-newHeightImage)/2;
			//var newMarginContainerHeaderCat = ((newheightSectionBlockTemplate-ingombroTitoloHeaderCat)-newHeightImage)/2;
			
			if(newMarginContainerHeaderCat < parseInt($('.bkg_first_block h1').css('margin-bottom'),10))
				newMarginContainerHeaderCat = 0;
				
			$('.sub_container_element_header_cat').css('margin-top',(newMarginContainerHeaderCat)+'px');
			

			if($('.block_page').length > 0 && $('.block_page').eq(0).attr('view') == "categorylistwatch")
				setDimensionCatWatch(obj);
			else
				obj.parents('.element_header_cat').find('.img_cat').width(newWidthImage).height(newHeightImage).hide().css('visibility','visible').fadeIn(500);
			

			obj.parents('.element_header_cat').find('.title_cat_header').fadeIn();
			obj.removeAttr('src').hide();
		});
	}

}

function setDimensionBkgBlock(obj)
{	
	var widthOriginalBkg = parseInt(obj.find('.img_appoggio_bkg_block_page').width(),10);
	var heightOriginalBkg = parseInt(obj.find('.img_appoggio_bkg_block_page').height(),10);
	
	//var newHeightBkg = Math.floor((heightOriginalBkg*widthContentTemplate)/widthOriginalBkg);
	var newHeightBkg = newheightSectionBlockTemplate;
	var newWidthBkg = Math.floor((widthOriginalBkg*newheightSectionBlockTemplate)/heightOriginalBkg);
	
	
	if(obj.find('.loader').css('display') != 'none')
	{
		obj.find('.loader').fadeOut(function(){
			if(obj.find('.img_bkg_block_page').attr('src') == undefined || obj.find('.img_bkg_block_page').attr('src') == "")
			{
				
				obj.find('.img_bkg_block_page').attr('src',obj.find('.img_appoggio_bkg_block_page').attr('src'));
			}
			//mostro l'immagine di bkg e il testo	
			//obj.find('.img_bkg_block_page').width(widthContentTemplate).height(newHeightBkg).fadeIn(function(){
			obj.find('.img_bkg_block_page').width(newWidthBkg).height(newHeightBkg).fadeIn(function(){
				
				obj.find('.wrap_txt_cover_category').width(parseInt(obj.find('.content_txt_cover_category').width(),10)).height(parseInt(obj.find('.content_txt_cover_category').height(),10)).css('margin-top', '-'+parseInt(obj.find('.content_txt_cover_category').height(),10)*0.5+'px').css('margin-left','-'+parseInt(obj.find('.content_txt_cover_category').width(),10)/2+'px');
				obj.find('.wrap_txt_cover_category').hide().css('visibility','visible').fadeIn(function(){});
			});
			
		});
	}
	else
	{
		obj.find('.wrap_txt_cover_category').width(parseInt(obj.find('.content_txt_cover_category').width(),10)).height(parseInt(obj.find('.content_txt_cover_category').height(),10)).css({marginTop: '-'+parseInt(obj.find('.content_txt_cover_category').width(),10)*0.5+'px', marginLeft: '-'+parseInt(obj.find('.content_txt_cover_category').width(),10)/2+'px'});
		//obj.find('.img_bkg_block_page').width(widthContentTemplate).height(newHeightBkg);
		obj.find('.img_bkg_block_page').width(newWidthBkg).height(newHeightBkg);
		
	}
}

function setDimensionOverBkgBlock(obj)
{
	
	var widthOriginalOverBkg = parseInt(obj.find('.img_appoggio_over_bkg_block_page').width(),10);
	var heightOriginalOverBkg = parseInt(obj.find('.img_appoggio_over_bkg_block_page').height(),10);
	
	var newHeight = (heightOriginalOverBkg*(widthColumnCoverWhithOverlayer))/widthOriginalOverBkg;
	
	//if(newHeight > MAX_HEIGHT_IMG_OVER_COVER_COLLECTIONS)
		//newHeight = MAX_HEIGHT_IMG_OVER_COVER_COLLECTIONS;
	
	newWidth = widthColumnCoverWhithOverlayer;
	
	if(newHeight > MAX_HEIGHT_IMG_OVER_COVER_COLLECTIONS)
	{
		var newWidth = (widthOriginalOverBkg*(MAX_HEIGHT_IMG_OVER_COVER_COLLECTIONS))/heightOriginalOverBkg;
		var newHeight = (heightOriginalOverBkg*newWidth)/widthOriginalOverBkg;
		var marginToptOverBkg = (newheightSectionBlockTemplate-newHeight)/2;
		obj.find('.img_over_bkg').css('margin-top',marginToptOverBkg+'px');
	}
	else if(newHeight < newheightSectionBlockTemplate)
	{
		var marginToptOverBkg = (newheightSectionBlockTemplate-newHeight)/2;
		obj.find('.img_over_bkg').css('margin-top',marginToptOverBkg+'px');
	}
		
	var marginLeftOverBkg = (widthColumnCoverWhithOverlayer-newWidth)/2;
	
	if(obj.find('.loader_over_cover_cat').css('display') != 'none')
	{
		  obj.find('.loader_over_cover_cat').css('display','none');
		  obj.find('.img_over_bkg').attr('src',obj.find('.img_appoggio_over_bkg_block_page').attr('src'));
		  obj.find('.img_over_bkg').width((newWidth)).height(newHeight).css('margin-left',marginLeftOverBkg+'px');
		  obj.find('.img_over_bkg').fadeIn(500);				  
	}
	else
		obj.find('.wrap_image_hover_bkg_cover_cat img.img_over_bkg').width((newWidth)).height(newHeight).css('margin-left',marginLeftOverBkg+'px');;
}

var setLoadImgSliderProdotti = false;

function setDimensionElementSliderFullScreen(obj)
{
	var nElementSliderProdotti = parseInt(obj.find('.cnt_slider_prodotti_list').find('ul').find('li').length,10);
	var ingombroTitolo = parseInt(obj.find('h1').height(),10)+parseInt(obj.find('h1').css('margin-top'),10)+parseInt(obj.find('h1').css('padding-top'),10)+parseInt(obj.find('h1').css('padding-bottom'),10)+parseInt(obj.find('h1').css('margin-bottom'),10);
	var ingombroSubTitolo = parseInt(obj.find('h2').height(),10)+parseInt(obj.find('h2').css('margin-top'),10)+parseInt(obj.find('h2').css('padding-top'),10)+parseInt(obj.find('h2').css('padding-bottom'),10)+parseInt(obj.find('h2').css('margin-bottom'),10);
	
	var newHeightElementSliderProdottiElenco = newheightSectionBlockTemplate-ingombroTitolo-ingombroSubTitolo;
	var newWidthElementSliderProdottiElenco = ((widthContentTemplate-(MARGIN_SLIDER_PRODOTTI*2))/MAX_ELEMENT_SLIDER_PRODOTTI_ELENCO);
	
	obj.find('.cnt_slider_prodotti_list').find('ul').find('li').width(newWidthElementSliderProdottiElenco).height(newHeightElementSliderProdottiElenco);
	
	if(!isMobile && !FORCE_NO_SLIDER_PRODUCT)
	{
		obj.find('.cnt_slider_prodotti_list').find('ul').width((newWidthElementSliderProdottiElenco*nElementSliderProdotti)+200).height(newHeightElementSliderProdottiElenco);
	}else
	{
		obj.find('.cnt_slider_prodotti_list').find('ul').width((widthContentTemplate-(MARGIN_SLIDER_PRODOTTI*2))).height(newHeightElementSliderProdottiElenco*(widthContentTemplate/nElementSliderProdotti));
		//widthContentTemplate nElementSliderProdotti newHeightElementSliderProdottiElenco
	}
	
	if(!setLoadImgSliderProdotti)
	{
		//attacco la load sulle immagini
		
		var i = 0;
		obj.find('.cnt_slider_prodotti_list').find('ul').find('li').each(function(){
			/*
			$(this).eq(i).find(".img_appoggio_load_slider_prod").load(function(){
				setDimensionImageSliderProduct($(this));
			});
			*/
			obj.find('.cnt_slider_prodotti_list').find('ul').find('li:eq('+i+')').find(".img_appoggio_load_slider_prod").load(function(){
				//alert($(this).length)
				if($(this).attr('img') != "")
				{
				
				$(this).parents('li').find('.item_slider_prod').attr('src',$(this).attr('src'));
				setDimensionImageSliderProduct($(this));
				}
			});
			
			$(this).find('.img_appoggio_load_slider_prod').attr('src',$(this).attr('img'));
			
			i++;
			
		});
		/*
		obj.find('.cnt_slider_prodotti_list').find('ul').find('li').find(".img_appoggio_load_slider_prod").load(function(){
			setDimensionImageSliderProduct($(this));
		})
		*/
		/*
		obj.find('.cnt_slider_prodotti_list').find('ul').find('li').each(function(){
			$(this).find('.img_appoggio_load_slider_prod').attr('src',$(this).attr('img'));
		});
		*/
	}
	else
	{
		//setDimensionImageSliderProduct($(".block_page").find('.cnt_slider_prodotti_list').find('ul').find('li').find(".img_appoggio_load_slider_prod"));
	}
	
}

function loaderElement(obj)
{
	var i = 0;
	obj.find('ul').find('li').each(function(){
		
		obj.find('ul').find('li:eq('+i+')').find(".item_slider_prod").load(function(){
			
			$(this).css('display','none').css('visibility','visible').fadeIn();
			$(this).parents('li').find('.loader').hide();
			//obj.find('ul').find('li').find('.loader').hide();
			
		});
		
		$(this).find(".item_slider_prod").attr('src',$(this).attr('img'));
		//obj.find('ul').find('li:eq('+i+')').find(".item_slider_prod").attr('src',$(this).attr('img'));
		i++;
		
	})
}

function setDimensionImageSliderProduct(obj)
{
	//alert('a')
	//alert('init setDimensionImageSliderProduct')
	var nElementSliderProdotti = parseInt($(".block_page").find('.cnt_slider_prodotti_list').find('ul').find('li').length,10);
	var newWidthElementSliderProdottiElenco = ((widthContentTemplate-(MARGIN_SLIDER_PRODOTTI*2))/MAX_ELEMENT_SLIDER_PRODOTTI_ELENCO);
	
	var newWidthWrapProductSlider;
	var widthTotalContainerProdotti;
	var marginWrapProdotti;
	if(isMobile || FORCE_NO_SLIDER_PRODUCT)
	{
		newWidthWrapProductSlider = Math.ceil(newWidthElementSliderProdottiElenco)*MAX_ELEMENT_SLIDER_PRODOTTI_ELENCO;
		widthTotalContainerProdotti = parseInt($('.sub_wrap_cnt_slider_prodotti_list').width(),10);
		marginWrapProdotti = (widthTotalContainerProdotti - newWidthWrapProductSlider)/2;
		//$('.sub_wrap_cnt_slider_prodotti_list ul').width(newWidthWrapProductSlider).css('left', marginWrapProdotti);	
	}

	var widthOriginalImg = 	parseInt(obj.width(),10);
	var heightOriginalImg = parseInt(obj.height(),10);
	
	var marginImageSlider = parseInt(obj.parents('li').find('.item_slider_prod').css('margin-left'),10)+parseInt(obj.parents('li').find('.item_slider_prod').css('margin-right'),10);
	
	var newWidthImageSliderProdotti = newWidthElementSliderProdottiElenco-marginImageSlider;
	var newHeightImage = Math.floor((newWidthImageSliderProdotti*heightOriginalImg)/widthOriginalImg);
	
	var maxHeightDescription = parseInt(obj.parents('li').find('p').height(),10);
	
	obj.parents('li').parents('ul').find('li').each(function(){
		if(maxHeightDescription < parseInt($(this).find('p').height(),10))
			maxHeightDescription = parseInt($(this).find('p').height(),10);		
	});
	
	var ingombroTitolo = parseInt(obj.parents('.bkg_first_block').find('h1').height(),10)+parseInt(obj.parents('.bkg_first_block').find('h1').css('margin-top'),10)+parseInt(obj.parents('.bkg_first_block').find('h1').css('padding-top'),10)+parseInt(obj.parents('.bkg_first_block').find('h1').css('padding-bottom'),10)+parseInt(obj.parents('.bkg_first_block').find('h1').css('margin-bottom'),10);
	var ingombroSubTitolo = parseInt(obj.parents('.bkg_first_block').find('h2').height(),10)+parseInt(obj.parents('.bkg_first_block').find('h2').css('margin-top'),10)+parseInt(obj.parents('.bkg_first_block').find('h2').css('padding-top'),10)+parseInt(obj.parents('.bkg_first_block').find('h2').css('padding-bottom'),10)+parseInt(obj.parents('.bkg_first_block').find('h2').css('margin-bottom'),10);
			
	var marginTopWrapSlider = (((newheightSectionBlockTemplate-ingombroTitolo-ingombroSubTitolo) - (newHeightImage+maxHeightDescription))/2) - ((ingombroTitolo-ingombroSubTitolo)*0.5);			
	
	if(marginTopWrapSlider < 10)
		marginTopWrapSlider = 10;
	
	if(isMobile || FORCE_NO_SLIDER_PRODUCT)
	{
		marginTopWrapSlider = 0;
		var row = Math.ceil((nElementSliderProdotti/MAX_ELEMENT_SLIDER_PRODOTTI_ELENCO));
		var heightWrapSlider = newHeightImage*row;
	}
	
	if(obj.parents('li').find('.loader').css('display') == 'none')
	{
		//console.log('loader display none');
		//alert('loader display none')
		if(!isMobile && !FORCE_NO_SLIDER_PRODUCT)
		{
			//console.log('not mobile');

			$('.sub_wrap_cnt_slider_prodotti_list').width(widthContentTemplate-(MARGIN_SLIDER_PRODOTTI*2)).css({marginLeft: MARGIN_SLIDER_PRODOTTI+'px', marginRight: MARGIN_SLIDER_PRODOTTI+'px'});
			obj.parents('li').width(newWidthElementSliderProdottiElenco).height(newHeightImage+maxHeightDescription);
			obj.parents('li').parents('ul').width(newWidthElementSliderProdottiElenco*nElementSliderProdotti).height(newHeightImage+maxHeightDescription);
			obj.parents('li').parents('ul').parent().height(newHeightImage+maxHeightDescription).css('margin-top',marginTopWrapSlider+"px");
			//obj.parents('li').parents('ul').css('margin-top',marginTopWrapSlider+"px");
			obj.parents('li').find('.item_slider_prod').width(newWidthImageSliderProdotti).height(newHeightImage);

		}else
		{
			//console.log('newWidthWrapProductSlider = '+newWidthWrapProductSlider+' - marginWrapProdotti = '+marginWrapProdotti);
			obj.parents('li').width(newWidthElementSliderProdottiElenco).height(newHeightImage+maxHeightDescription*2);
			
			//obj.parents('li').parents('ul').width(widthContentTemplate).height();
			obj.parents('li').parents('ul').width(newWidthWrapProductSlider).height();

			//obj.parents('li').parents('ul').css('margin-top',marginTopWrapSlider+"px");
			obj.parents('li').parents('ul').css({'margin-top': marginTopWrapSlider+"px", 'left': marginWrapProdotti+"px"});
			
			obj.parents('li').find('.item_slider_prod').width(newWidthImageSliderProdotti).height(newHeightImage);
			
			obj.find('.cnt_slider_prodotti_list').find('ul').width(widthContentTemplate).height(heightWrapSlider+((maxHeightDescription*2)*row));
			//obj.find('.cnt_slider_prodotti_list').find('ul').width(newWidthWrapProductSlider).height(heightWrapSlider+((maxHeightDescription*2)*row)).css('left', marginWrapProdotti+"px");

			obj.find('.cnt_slider_prodotti_list').parent().height(heightWrapSlider+ingombroTitolo+ingombroSubTitolo+((maxHeightDescription*2)*row));
			obj.find('.cnt_slider_prodotti_list').find('ul').parents('.block_page').height(heightWrapSlider+ingombroTitolo+ingombroSubTitolo+((maxHeightDescription*2)*row));
			
			//$('.sub_wrap_cnt_slider_prodotti_list ul').width(newWidthWrapProductSlider).css('left', marginWrapProdotti+"px");
			setScroller();
		}
	}
	else
	{
		//alert('loader display inline')
		obj.parents('li').find('.loader').fadeOut(function(){	

			if(!isMobile && !FORCE_NO_SLIDER_PRODUCT)
			{
				//$('.cnt_slider_prodotti_list').width(widthContentTemplate-50).css('padding-left',50+'px');
				$('.sub_wrap_cnt_slider_prodotti_list').width(widthContentTemplate-(MARGIN_SLIDER_PRODOTTI*2)).css({marginLeft: MARGIN_SLIDER_PRODOTTI+'px', marginRight: MARGIN_SLIDER_PRODOTTI+'px'});
				//console.log(widthContentTemplate-(MARGIN_SLIDER_PRODOTTI*2))	
				//alert('not mobile')
				//alert(obj.parents('li').find('.item_slider_prod').length);
				//obj.parents('li').find('.item_slider_prod').attr('src',obj.parents('li').attr('img'));
				obj.parents('li').find('.item_slider_prod').width(newWidthImageSliderProdotti).height(newHeightImage);
				obj.parents('li').find('.item_slider_prod').fadeIn();
				obj.parents('li').find('p').hide().css('visibility','visible').fadeIn();
				
				obj.parents('li').parents('ul').height(newHeightImage+maxHeightDescription);
				obj.parents('li').parents('ul').parent().height(newHeightImage+maxHeightDescription).css('margin-top',marginTopWrapSlider+"px");;
				obj.parents('li').height(newHeightImage+maxHeightDescription);
				
				obj.parents('li').parents('ul').parents('.cnt_slider_prodotti_list').find('.arrow_sx, .arrow_dx').css('visibility','visible');
				
				//obj.parents('li').parents('ul').css('margin-top',marginTopWrapSlider+"px");			
			}
			else
			{
				//obj.parents('li').find('.item_slider_prod').attr('src',obj.parents('li').attr('img'));
				obj.parents('li').find('.item_slider_prod').width(newWidthImageSliderProdotti).height(newHeightImage);
				obj.parents('li').find('.item_slider_prod').fadeIn();
				obj.parents('li').find('p').hide().css('visibility','visible').fadeIn();
				
				obj.parents('li').parents('ul').css({'margin-top':marginTopWrapSlider+"px" , 'left':marginWrapProdotti+"px"});
				
				obj.parents('li').width(newWidthElementSliderProdottiElenco).height(newHeightImage+maxHeightDescription*2);
				
				//obj.parents('li').parents('ul').width(widthContentTemplate).height(heightWrapSlider+((maxHeightDescription*2)*row));
				obj.parents('li').parents('ul').width(newWidthWrapProductSlider).height(heightWrapSlider+((maxHeightDescription*2)*row));

				obj.parents('li').parents('ul').parent().height(heightWrapSlider+ingombroTitolo+ingombroSubTitolo+((maxHeightDescription*2)*row));
				obj.parents('li').parents('ul').parents('.block_page').height(heightWrapSlider+ingombroTitolo+ingombroSubTitolo+((maxHeightDescription*2)*row));	
				
				//$('.sub_wrap_cnt_slider_prodotti_list ul').width(newWidthWrapProductSlider).css('left', marginWrapProdotti);		
				setScroller();
			}
			
		});	
	}
	
}
var clickOnArrow = false;
var indexElementActiveGalleryProdotti = 0;
var waitMove = false;
function setDimensionGalleryProdotti()
{	
	var widthImageOriginal = parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li.active').find('.appoggio_gallery_prodotti').width(),10);
	var heightImageOriginal = parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li.active').find('.appoggio_gallery_prodotti').height(),10);
	
	var ingombroTitolo = parseInt($('.sez_dettaglio_prod').find('h1').height(),10)+parseInt($('.sez_dettaglio_prod').find('h1').css('margin-top'),10)+parseInt($('.sez_dettaglio_prod').find('h1').css('padding-top'),10)+parseInt($('.sez_dettaglio_prod').find('h1').css('padding-bottom'),10)+parseInt($('.sez_dettaglio_prod').find('h1').css('margin-bottom'),10);
	var ingombroSubTitolo = parseInt($('.sez_dettaglio_prod').find('h2').height(),10)+parseInt($('.sez_dettaglio_prod').find('h2').css('margin-top'),10)+parseInt($('.sez_dettaglio_prod').find('h2').css('padding-top'),10)+parseInt($('.sez_dettaglio_prod').find('h2').css('padding-bottom'),10)+parseInt($('.sez_dettaglio_prod').find('h2').css('margin-bottom'),10);

	if($('.cnt_slider_prodotti_gallery').find('.loader').css('display') != 'none')
	{
		$('.cnt_slider_prodotti_gallery').find('.loader').fadeOut();
	}
	
	if(parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li.active').attr('isFullBkg'),10) == 1)	
	{
		var newWidth = widthContentTemplate;
		var newHeight = Math.floor((newWidth*heightImageOriginal)/widthImageOriginal);
		
		if(newHeight < newheightSectionBlockTemplate)
		{
			newWidth = (widthImageOriginal*(newheightSectionBlockTemplate))/heightImageOriginal;
			newHeight = newheightSectionBlockTemplate;
		}
		
		$('.cnt_slider_prodotti_gallery').find('ul').find('li.active').find('.item_slider_prod_gallery').attr('src',$('.cnt_slider_prodotti_gallery').find('ul').find('li.active').find('.appoggio_gallery_prodotti').attr('src')).width(newWidth).height(newHeight);
		$('.cnt_slider_prodotti_gallery').find('ul').find('li.active').find('.item_slider_prod_gallery').fadeIn(function(){
			
		});
		$('.cnt_slider_prodotti_gallery .arrow_sx, .cnt_slider_prodotti_gallery .arrow_dx').css('margin-top',"-25px");
		//$('.wrap_find').addClass('alto');
		//$('.sfuma').fadeIn();
	}
	else
	{
		$('.cnt_slider_prodotti_gallery .arrow_sx, .cnt_slider_prodotti_gallery .arrow_dx').css('margin-top',"-25px");
		//$('.wrap_find').removeClass('alto');
		//$('.sfuma').hide();
		
		var newHeight = newheightSectionBlockTemplate-ingombroTitolo-ingombroSubTitolo-MARGIN_TOP_ELEMENT_GALLERY_PROD;
		var newWidth = Math.floor((widthImageOriginal*newHeight)/heightImageOriginal);
		
		$('.cnt_slider_prodotti_gallery').find('ul').find('li.active').find('.item_slider_prod_gallery').attr('src',$('.cnt_slider_prodotti_gallery').find('ul').find('li.active').find('.appoggio_gallery_prodotti').attr('src')).width(newWidth).height(newHeight).css('margin-top',ingombroTitolo+ingombroSubTitolo+MARGIN_TOP_ELEMENT_GALLERY_PROD);
		
		$('.cnt_slider_prodotti_gallery').find('ul').find('li.active').find('.item_slider_prod_gallery').fadeIn(function(){
			
		});
		
		//gestisco immagine luminova
		if($('.cnt_slider_prodotti_gallery').find('ul').find('li.active').find('.luminova_container').length > 0)
		{
			$('.cnt_slider_prodotti_gallery').find('ul').find('li.active').find('.luminova_container').find('.luminova_img').width(newWidth).height(newHeight).css('margin-top',ingombroTitolo+ingombroSubTitolo+MARGIN_TOP_ELEMENT_GALLERY_PROD);
			
		}
		
		if($('.cnt_slider_prodotti_gallery .arrow_sx').css('margin-top') == "-25px")
		$('.cnt_slider_prodotti_gallery .arrow_sx, .cnt_slider_prodotti_gallery .arrow_dx').css('margin-top',"+="+((MARGIN_TOP_ELEMENT_GALLERY_PROD+ingombroTitolo+ingombroSubTitolo)/2)+"px");
	}
	
}

var currentElementGalleryProdotti = -1;
function goGalleryProdottiByCursor(index)
{
	if(intervallAutoSlide != null || intervallAutoSlide != "")
	{
		clearInterval(intervallAutoSlide);
		intervallAutoSlide = "";
	}
	
	if(index == "autoplay")
	{
		var nImgGallery = parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li').length,10);
		var currentImgActiveIndex = parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li.active').index(),10);
		var newIndexGallery = currentImgActiveIndex+1;
		if(newIndexGallery == nImgGallery)
			newIndexGallery = 0;
		
		index = newIndexGallery;
	}
	
	dataLayer.push({"event": "alternateView"});	
	
	if(!waitMove)
	{
		var indexClick = index;
		var ingombroTitolo = parseInt($('.sez_dettaglio_prod').find('h1').height(),10)+parseInt($('.sez_dettaglio_prod').find('h1').css('margin-top'),10)+parseInt($('.sez_dettaglio_prod').find('h1').css('padding-top'),10)+parseInt($('.sez_dettaglio_prod').find('h1').css('padding-bottom'),10)+parseInt($('.sez_dettaglio_prod').find('h1').css('margin-bottom'),10);
		var ingombroSubTitolo = parseInt($('.sez_dettaglio_prod').find('h2').height(),10)+parseInt($('.sez_dettaglio_prod').find('h2').css('margin-top'),10)+parseInt($('.sez_dettaglio_prod').find('h2').css('padding-top'),10)+parseInt($('.sez_dettaglio_prod').find('h2').css('padding-bottom'),10)+parseInt($('.sez_dettaglio_prod').find('h2').css('margin-bottom'),10);
		
		indexElementActive = $('.cnt_slider_prodotti_gallery').find('ul').find('li.active').index();
		
		
		if(index == indexElementActive)
			return;
		
		//currentElementGalleryProdotti = index;
		
		/*
		if(index > indexElementActive)
			index = index+1;
		else
			index = index-1;
		*/
		if(parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).attr('isFullBkg'),10) == 1)	
		{
			//$('.wrap_find').addClass('alto');
			//$('.sfuma').fadeIn();
		}
		else
		{
			//$('.sfuma').hide();
			//$('.wrap_find').removeClass('alto');
		}
		
		$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive).fadeOut(function(){			
			
			$(".cursor_gallery").find('a.active').removeClass('active');
			$(".cursor_gallery").find('a').eq(indexClick).addClass('active');
			
			$('.cnt_slider_prodotti_gallery').find('ul').find('li.active').removeClass('active');
			$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).addClass('active');
			
			if(parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li.active').attr('isFullBkg'),10) == 1)
			{
				$('.cnt_slider_prodotti_gallery .arrow_sx, .cnt_slider_prodotti_gallery .arrow_dx').css('margin-top',"-25px");
			}
			else
			{
				if($('.cnt_slider_prodotti_gallery .arrow_sx').css('margin-top') == "-25px")
				$('.cnt_slider_prodotti_gallery .arrow_sx, .cnt_slider_prodotti_gallery .arrow_dx').css('margin-top',"+="+((MARGIN_TOP_ELEMENT_GALLERY_PROD+ingombroTitolo+ingombroSubTitolo)/2)+"px");
			}
			waitMove = false;
			
			//se l'immaguine non è caricata la carico
			if($('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).find('.appoggio_gallery_prodotti').attr('src') == "" || $('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).find('.appoggio_gallery_prodotti').attr('src') == undefined)
			{
				$('.cnt_slider_prodotti_gallery').find('.loader').fadeIn();
				$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).find('.appoggio_gallery_prodotti').attr('src',$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).attr('img'));
			}
			else
			{
				if(parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).attr('isFullBkg'),10) == 1)	
				{
					var heightImageOriginal = parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).find('.item_slider_prod_gallery').height(),10);
					var widthImageOriginal = parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).find('.item_slider_prod_gallery').width(),10);
					
					var newWidth = widthContentTemplate;
					var newHeight = Math.floor((newWidth*heightImageOriginal)/widthImageOriginal);
					
					$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).hide().fadeIn();
					$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).find('.item_slider_prod_gallery').width(newWidth).height(newHeight);
					//$('.wrap_find').addClass('alto');
					//$('.sfuma').fadeIn();
				}
				else
				{
					var widthImageOriginal = parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).find('.item_slider_prod_gallery').width(),10);
					var heightImageOriginal = parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).find('.item_slider_prod_gallery').height(),10);
					var newHeight = newheightSectionBlockTemplate-ingombroTitolo-ingombroSubTitolo-MARGIN_TOP_ELEMENT_GALLERY_PROD;
					var newWidth = Math.floor((widthImageOriginal*newHeight)/heightImageOriginal);
					$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).hide().fadeIn();
					$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).find('.item_slider_prod_gallery').width(newWidth).height(newHeight);
				}
			}
			
			//gestisco la visibilità dei social video solo nella pagina del dettaglio orologio
			if($('.block_page[view="orologio"]').length > 0)
			{
				if($('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).attr('data-videopam') != "" && $('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(index).attr('data-videopam') != undefined)
				{
					showFunctionShareVideoPam();
				}
				else
				{
					hideFunctionShareVideoPam();	
				}
			}

			
		});	
	}
}

function goGalleryProdotti(direction, index)
{
	//alert(index + " " + direction)
	if(index == undefined || index == "")
		indexElementActive = $('.cnt_slider_prodotti_gallery').find('ul').find('li.active').index();
	else
		indexElementActive = index;
	
	var numElement = parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li').length,10);
	
	$('.cnt_slider_prodotti_gallery').find('.loader').fadeIn();
	indexElementActiveGalleryProdotti = indexElementActive;
	
	var ingombroTitolo = parseInt($('.sez_dettaglio_prod').find('h1').height(),10)+parseInt($('.sez_dettaglio_prod').find('h1').css('margin-top'),10)+parseInt($('.sez_dettaglio_prod').find('h1').css('padding-top'),10)+parseInt($('.sez_dettaglio_prod').find('h1').css('padding-bottom'),10)+parseInt($('.sez_dettaglio_prod').find('h1').css('margin-bottom'),10);
	var ingombroSubTitolo = parseInt($('.sez_dettaglio_prod').find('h2').height(),10)+parseInt($('.sez_dettaglio_prod').find('h2').css('margin-top'),10)+parseInt($('.sez_dettaglio_prod').find('h2').css('padding-top'),10)+parseInt($('.sez_dettaglio_prod').find('h2').css('padding-bottom'),10)+parseInt($('.sez_dettaglio_prod').find('h2').css('margin-bottom'),10);
	
	if($('.cnt_slider_prodotti_gallery').find('.loader').css('display') != 'none')
	{
		$('.cnt_slider_prodotti_gallery').find('.loader').fadeOut();
	}
	
	if(!waitMove)
	{
		if(direction)	
		{
			if((indexElementActive+2)>numElement)
			{	
				//goGalleryProdotti(true,-1);
				return;
			}
			
			waitMove = true;
			
			if(parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive+1).attr('isFullBkg'),10) == 1)
			{	
				//$('.wrap_find').addClass('alto');
				//$('.sfuma').fadeIn();
			}
			else
			{
				//$('.wrap_find').removeClass('alto');
				//$('.sfuma').hide();
			}
			
			$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive).fadeOut(function(){
				
				$(".cursor_gallery").find('a.active').removeClass('active');
				$(".cursor_gallery").find('a').eq(indexElementActive+1).addClass('active');
				
				$('.cnt_slider_prodotti_gallery').find('ul').find('li.active').removeClass('active');
				$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive+1).addClass('active');
				
				if(parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li.active').attr('isFullBkg'),10) == 1)
				{
					$('.cnt_slider_prodotti_gallery .arrow_sx, .cnt_slider_prodotti_gallery .arrow_dx').css('margin-top',"-25px");
				}
				else
				{
					if($('.cnt_slider_prodotti_gallery .arrow_sx').css('margin-top') == "-25px")
					$('.cnt_slider_prodotti_gallery .arrow_sx, .cnt_slider_prodotti_gallery .arrow_dx').css('margin-top',"+="+((MARGIN_TOP_ELEMENT_GALLERY_PROD+ingombroTitolo+ingombroSubTitolo)/2)+"px");
				}
				
				if($('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive+1).find('.appoggio_gallery_prodotti').attr('src') == "" || $('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive+1).find('.appoggio_gallery_prodotti').attr('src') == undefined)
				$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive+1).find('.appoggio_gallery_prodotti').attr('src',$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive+1).attr('img'));
				else
				$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive+1).hide().fadeIn();
				
				clickOnArrow = true;
				waitMove = false;
				
			});	
			
		}
		else
		{
			if(indexElementActive == 0)
			{
				//goGalleryProdotti(true,numElement-1);
				return;
			}
			
			waitMove = true;
			
			if(parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive-1).attr('isFullBkg'),10) == 1)
			{	
				//$('.wrap_find').addClass('alto');
				//$('.sfuma').fadeIn();
			}
			else
			{
				//$('.wrap_find').removeClass('alto');
				//$('.sfuma').hide();
			}
			
			$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive).fadeOut(function(){
				
				$(".cursor_gallery").find('a.active').removeClass('active');
				$(".cursor_gallery").find('a').eq(indexElementActive-1).addClass('active');
				
				$('.cnt_slider_prodotti_gallery').find('ul').find('li.active').removeClass('active');
				$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive-1).addClass('active');
				
				if(parseInt($('.cnt_slider_prodotti_gallery').find('ul').find('li.active').attr('isFullBkg'),10) == 1)
				{
					$('.cnt_slider_prodotti_gallery .arrow_sx, .cnt_slider_prodotti_gallery .arrow_dx').css('margin-top',"-25px");
				}
				else
				{
					if($('.cnt_slider_prodotti_gallery .arrow_sx').css('margin-top') == "-25px")
					$('.cnt_slider_prodotti_gallery .arrow_sx, .cnt_slider_prodotti_gallery .arrow_dx').css('margin-top',"+="+((MARGIN_TOP_ELEMENT_GALLERY_PROD+ingombroTitolo+ingombroSubTitolo)/2)+"px");
				}
				
				if($('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive-1).find('.appoggio_gallery_prodotti').attr('src') == "" || $('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive-1).find('.appoggio_gallery_prodotti').attr('src') == undefined || $('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive-1).find('.appoggio_gallery_prodotti').attr('src') == "undefined")
				{					
					$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive-1).find('.appoggio_gallery_prodotti').attr('src',$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive+1).attr('img'));
				}
				else
				{
					$('.cnt_slider_prodotti_gallery').find('ul').find('li').eq(indexElementActive-1).hide().fadeIn();
				}
				
				clickOnArrow = true;
				waitMove = false;
				
			});	
		}
	}
}

function openCorrelati()
{
	if(correlatiOpen)
	{
		var heightCorrelati = parseInt($(".sub_wrap_correlati").height(),10);
		$('.wrap_prod_correlati').animate({
			height: "0px"
		},500,function(){setScroller();})
		correlatiOpen = false;
		$(".bt_correlati").removeClass('open');
	}
	else
	{
		
		dataLayer.push({"event": "clickViewAll"});
		var heightCorrelati = parseInt($(".sub_wrap_correlati").height(),10);
		$('.wrap_prod_correlati').animate({
			height: heightCorrelati+"px"
		},500,function(){setScroller();})
		correlatiOpen = true;
		$(".bt_correlati").addClass('open');
	}
}

function setPositionListAccessori()
{
	//gestisco la dimensione del wrapper dei prodotti correlati
	var numCorrelati = parseInt($('.accessori_list ul').find('li').length,10);
	var elementRiga = Math.floor((widthContentTemplate-80)/WIDTH_ACCESSORI_CONTAINER);
	if(elementRiga>numCorrelati)
		elementRiga = numCorrelati;	
	
	var righe = Math.ceil(numCorrelati/elementRiga);
	$('.accessori_list ul').width((Math.abs(parseInt(elementRiga,10))*(WIDTH_ACCESSORI_CONTAINER+2)));
	
	var maxHeight = 0;
	$('.accessori_list ul li').each(function(){
		
		if(($(this).find('img').height() + parseInt($(this).find('img').css('margin-bottom'),10) + $(this).find('a').find('p').height()) > maxHeight)
			maxHeight = $(this).find('img').height() + parseInt($(this).find('img').css('margin-bottom'),10) + $(this).find('a').find('p').height();
	});
	$('.accessori_list ul li').find('a').height(maxHeight);
	
	setScroller();
	/*
	if(correlatiOpen)
	{
		//alert(righe + '*' + HEIGHT_PROD_CORRELATI)
		$('.wrap_prod_correlati').height(righe*HEIGHT_PROD_CORRELATI);
	}
	*/
}

function setPositionList(obj,widthElement)
{
	//gestisco la dimensione del wrapper dei prodotti correlati
	/*
	var numCorrelati = parseInt(obj.find('li').length,10);
	var elementRiga = Math.floor((widthContentTemplate-80)/(widthElement+2));
	if(elementRiga>numCorrelati)
		elementRiga = numCorrelati;	
	
	var righe = Math.ceil(numCorrelati/elementRiga);
	
	obj.width((Math.abs(parseInt(elementRiga,10))*widthElement)+2);
	*/
	
	//gestisco la dimensione del wrapper dei prodotti correlati
	var numCorrelati = parseInt(obj.find('li').length,10);
	
	var elementRiga = Math.floor((widthContentTemplate)/(widthElement+2));
	if(elementRiga>numCorrelati)
		elementRiga = numCorrelati;	
	
	var righe = Math.ceil(numCorrelati/elementRiga);
	
	obj.width((Math.abs(parseInt(elementRiga,10))*widthElement)+(elementRiga*2));
	
	setScroller();
	
	/*
	if(correlatiOpen)
	{
		//alert(righe + '*' + HEIGHT_PROD_CORRELATI)
		$('.wrap_prod_correlati').height(righe*HEIGHT_PROD_CORRELATI);
	}
	*/
}


function setPositionListPam()
{
	//gestisco la dimensione del wrapper dei prodotti correlati
	var numCorrelati = parseInt($('.pam_list ul').find('li').length,10);
	var elementRiga = Math.floor((widthContentTemplate-80)/WIDTH_PAM_LIST_CONTAINER);
	if(elementRiga>numCorrelati)
		elementRiga = numCorrelati;	
	
	var righe = Math.ceil(numCorrelati/elementRiga);
	
	$('.pam_list ul').width((Math.abs(parseInt(elementRiga,10))*WIDTH_PAM_LIST_CONTAINER)+2);
	
	/*
	var maxHeight = 0;
	$('.accessori_list ul li').each(function(){
		if(($(this).find('img').height() + $(this).find('a').find('p').height()) > maxHeight)
			maxHeight = $(this).find('img').height() + $(this).find('a').find('p').height();
	});
	$('.accessori_list ul li').find('a').height(maxHeight);
	*/
	/*
	if(correlatiOpen)
	{
		//alert(righe + '*' + HEIGHT_PROD_CORRELATI)
		$('.wrap_prod_correlati').height(righe*HEIGHT_PROD_CORRELATI);
	}
	*/
}

function setWidthColumnTabDeclinazioneAccessorio()
{
	//var newWidthColumn = ((widthContentTemplate-(MARGIN_TAB_PRODOTTO*2)-WIDTH_COLUMN_TEXTURE_ACCESSORI-(MARGIN_COLUMN_ACCESSORI_TAB*NUM_COLUMN_ACCESSORI_TAB))/NUM_COLUMN_ACCESSORI_TAB);
	var tableWidth = parseInt($('.wrap_content_tab_dett_prod').width(), 10);
	var newWidthColumn = ((tableWidth-(MARGIN_TAB_PRODOTTO*2)-WIDTH_COLUMN_TEXTURE_ACCESSORI-(MARGIN_COLUMN_ACCESSORI_TAB*NUM_COLUMN_ACCESSORI_TAB))/NUM_COLUMN_ACCESSORI_TAB);
	//console.log(newWidthColumn);
	$('.wrap_declinazione_accessori').find('.column_declinazione_accessori').each(function(){
		
		if(!$(this).hasClass('texture'))
			$(this).width(newWidthColumn);
		
	});
	$('.wrap_title_declinazione_accessori').find('.column_declinazione_accessori').width(newWidthColumn);
	
	
	//alert($(".wrap_declinazione_accessori").width())
}

function setWidthColumnTabAccessorioPam()
{
	var maxWidthColumnNome = 0;
	$('.nome_accessorio_pam').each(function(){
		
		if(maxWidthColumnNome < parseInt($(this).width(),10))
			maxWidthColumnNome = parseInt($(this).width(),10);
		
	});
	$('.nome_accessorio_pam').width(maxWidthColumnNome);
	$('.title_nome_accessorio_pam').width(maxWidthColumnNome);
	//WIDTH_LINK_DETAIL_TAB_ACCESSORI_PAM
}

var righeActive = 4;
function loadMore(elementWrapClass, fromResize)
{
	if(fromResize == null)
		fromResize = false;
		
	var righeStep = 4;
	
	var marginWrap = parseInt($('.'+elementWrapClass).find('div').eq(0).css('margin-left'),10)+parseInt($('.'+elementWrapClass).find('div').eq(0).css('margin-right'),10);
	
	var widthElemet = ($('.'+elementWrapClass).find('ul').find('li').width() + parseInt($('.'+elementWrapClass).find('ul').find('li').css('padding-right'),10) + parseInt($('.'+elementWrapClass).find('ul').find('li').css('padding-left'),10) + parseInt($('.'+elementWrapClass).find('ul').find('li').css('margin-left'),10) + parseInt($('.'+elementWrapClass).find('ul').find('li').css('margin-right'),10))+2;
	
	var heightElemet = $('.'+elementWrapClass).find('ul').find('li').height() + parseInt($('.'+elementWrapClass).find('ul').find('li').css('padding-top'),10) + parseInt($('.'+elementWrapClass).find('ul').find('li').css('padding-bottom'),10) + parseInt($('.'+elementWrapClass).find('ul').find('li').css('margin-bottom'),10) + parseInt($('.'+elementWrapClass).find('ul').find('li').css('margin-top'),10);
	
	var numElement = parseInt($('.'+elementWrapClass).find('ul').find('li').length,10);
	var elementRiga = Math.floor((widthContentTemplate-marginWrap)/widthElemet);
	//alert(elementRiga)
	
	if(elementRiga>numElement)
		elementRiga = numElement;	
	var righe = Math.ceil(numElement/elementRiga);
	
	if(righeActive >= righe)
		return;
	
	var newHeight = 0;
	
	if((righeActive+righeStep) > righe)
	{
		newHeight = heightElemet*(righe-righeActive);
		if(!fromResize)
		righeActive += (righe-righeActive);
	}
	else
	{
		newHeight = heightElemet*righeStep
		if(!fromResize)
		righeActive += righeStep;
	}
	
	if(righeActive >= righe)
		$('.wrap_bt_loader').hide();
	else
		$('.wrap_bt_loader').show();
	
	if(fromResize)
	{
		
		if( (elementRiga*righeActive) < numElement )
		{
			$('.wrap_bt_loader').show();
		}
		else
		{
			$('.wrap_bt_loader').hide();
		}
		
		if((righeActive*heightElemet) > (righe*heightElemet))
			$('.'+elementWrapClass).css('height',(righe*heightElemet));
		/*
		var tmpHeight = 0;
		if(newHeight < parseInt($('.'+elementWrapClass).height(),10))
		{
			tmpHeight = newHeight;
			alert(tmpHeight + ' su')
		}
		else
		{
			tmpHeight = '+='+newHeight;
			alert(tmpHeight + ' giu')
		}
		
		$('.'+elementWrapClass).css('height',tmpHeight);
		setScroller();
		*/
		
	}
	else
	{	
		$('.'+elementWrapClass).animate({
			height: "+="+(newHeight)
		},100,function(){
			
			setScroller();
			goAnchor('',(newHeight+60));
			
		})
	}
}

function checkloadMore(elementWrapClass)
{
	
	var marginWrap = parseInt($('.'+elementWrapClass).find('div').eq(0).css('margin-left'),10)+parseInt($('.'+elementWrapClass).find('div').eq(0).css('margin-right'),10);
	
	var widthElemet = ($('.'+elementWrapClass).find('ul').find('li').width() + parseInt($('.'+elementWrapClass).find('ul').find('li').css('padding-right'),10) + parseInt($('.'+elementWrapClass).find('ul').find('li').css('padding-left'),10) + parseInt($('.'+elementWrapClass).find('ul').find('li').css('margin-left'),10) + parseInt($('.'+elementWrapClass).find('ul').find('li').css('margin-right'),10))+2;
	
	var heightElemet = $('.'+elementWrapClass).find('ul').find('li').height() + parseInt($('.'+elementWrapClass).find('ul').find('li').css('padding-top'),10) + parseInt($('.'+elementWrapClass).find('ul').find('li').css('padding-bottom'),10) + parseInt($('.'+elementWrapClass).find('ul').find('li').css('margin-bottom'),10) +  + parseInt($('.'+elementWrapClass).find('ul').find('li').css('margin-top'),10);
	
	var numElement = parseInt($('.'+elementWrapClass).find('ul').find('li').length,10);
	var elementRiga = Math.floor((widthContentTemplate-marginWrap)/widthElemet);
	
	if(elementRiga > numElement)
		elementRiga = numElement;	
		
	var righe = Math.ceil(numElement/elementRiga);
	
	if( righe < righeActive)
	{
		$('.wrap_bt_loader').hide();
		
		$('.'+elementWrapClass).height(righe*heightElemet);
		setScroller();
	}
	
}

var apiScroller;
function setScroller()
{
	//$('body').css('overflow','auto');
	heightContentScroller = parseInt($(".sub_content_scroller_element").height(),10);	
	//alert(heightContentScroller + " " + $(".sub_content_scroller_element").children('.block_page').height())
	if(heightContentScroller < window_height-HEIGHT_FOOTER)
		heightContentScroller = window_height-HEIGHT_FOOTER;
	$(".content_scroller_element").height(heightContentScroller+'px');
	$(".scroller_element").height(((parseInt($(".total_wrap_page").height(),10))-HEIGHT_FOOTER)+'px');
	//alert($("#section_template").width())
	$(".scroller_element").width(parseInt($("#section_template").width(),10)+'px');
	
	//sub_content_scroller_element

	var pane = $('.scroller_element');
	if(isMobile)
	{
		pane.jScrollPane(
			{
				//animateScroll: true
				//animateEase: 'easeInOutExpo'
				//animateDuration: 800
			}
		);
	}
	else
	{
		pane.jScrollPane(
			{
				animateScroll: true,
				animateEase: 'easeInOutExpo',
				mouseWheelSpeed: 100,
				animateDuration: 800
			}
		);
	}
	
	apiScroller = pane.data('jsp');
	
	var newWidthSectionTemplate = Math.floor((parseInt($(".total_wrap_page").width(),10)-widthMenu)-5);
	
	if($('.jspVerticalBar').length > 0)
		$('.jspPane').width(newWidthSectionTemplate+"px");
	
	//$('.scroller_element').jScrollPane();
	//$(".scroller_element .jspContainer").width((window_width-WIDTH_MENU_OPEN)+'px');
	//$(".scroller_element .jspContainer").find('.jspPane').width((window_width-WIDTH_MENU_OPEN-15)+'px');
}

function goAnchor(obj,top)
{
	if(obj != "")
	apiScroller.scrollTo(0, parseInt(obj.position().top,10));
	else if(top == 0)
	apiScroller.scrollTo(0, top);
	else
	apiScroller.scrollTo(0, (heightContentScroller-top));
	
}

function gotoCoverCategory(id)
{
	apiScroller.scrollTo(0, parseInt($('.block_page[coverCopertina="'+id+'"]').position().top,10));
}

function setWidthContentProdCorrelatiMovements()
{
	//gestisco la dimensione del wrapper dei prodotti correlati
	var numCorrelati = parseInt($('.sub_wrap_correlati_movimento ul').find('li').length,10);
	
	//prendo i padding del contenitore
	var pl = parseInt($("#tab_dett_prodotto").css('padding-left'),10);
	var pr = parseInt($("#tab_dett_prodotto").css('padding-right'),10);
	
	var tmpWidthContentCorrelati = widthContentTemplate - pl - pr;
	
	var elementRiga = Math.floor(tmpWidthContentCorrelati/(WIDTH_PROD_CORRELATI+(MARGIN_PROD_CORRELATI*2)));
	
	if(elementRiga>numCorrelati)
		elementRiga = numCorrelati;	
	
	var righe = Math.ceil(numCorrelati/elementRiga);
	
	$('.sub_wrap_correlati_movimento ul').width(Math.abs(parseInt(elementRiga,10))*(WIDTH_PROD_CORRELATI+(MARGIN_PROD_CORRELATI*2)));
}	

//gestione menu
$('.menu li a').live('click',function(){	
	var idMenu = $(this).attr('idMenu');
	openMenu(idMenu,-1);
});

function openMenu(idMenu,adjustOpen)
{
	if($(".menu li a[idParent='"+idMenu+"']").length == 0)
	return;
	
	if(adjustOpen==-1)
	{
		if($(".menu li a[idParent='"+idMenu+"']").parent().parent().hasClass('open'))
		{
			$(".menu li a[idMenu='"+idMenu+"']").removeClass('active');
			
			var heightMenuOpen = (parseInt($(".menu li a[idParent='"+idMenu+"']").parent().parent().height(),10)
			+parseInt($(".menu li a[idParent='"+idMenu+"']").parent().parent().css('padding-top'),10)
			+parseInt($(".menu li a[idParent='"+idMenu+"']").parent().parent().css('padding-bottom'),10))*-1
			
			$(".menu li a[idParent='"+idMenu+"']").parent().parent().animate({
				height: '0px'
			}, 300, function(){
				$(".menu li a[idParent='"+idMenu+"']").parent().parent().removeClass('open');	
			});
			
			if($(".menu li a[idMenu='"+idMenu+"']").parents('ul').length == 2)
			{
				openMenu($(".menu li a[idMenu='"+idMenu+"']").parents('ul:eq(0)').parent().find('a').attr('idMenu'),heightMenuOpen)
			}
			if($(".menu li a[idParent='"+idMenu+"']").parent().parent().find('ul.open').length > 0)
			{
				$(".menu li a[idMenu='"+$(".voce_menu[idParent='"+idMenu+"']").parent().parent().find('ul.open').parent().find('a').attr('idMenu')+"']").removeClass('active');	
				$(".menu li a[idParent='"+$(".voce_menu[idParent='"+idMenu+"']").parent().parent().find('ul.open').parent().find('a').attr('idMenu')+"']").parent().parent().css({height: '0px'});
				$(".menu li a[idParent='"+$(".voce_menu[idParent='"+idMenu+"']").parent().parent().find('ul.open').parent().find('a').attr('idMenu')+"']").parent().parent().removeClass('open');		
			}
			return;
		}
	}
	
	var newHeightSubMenu = 0;
	if(adjustOpen!=-1)
		newHeightSubMenu = adjustOpen;
		
	$(".menu li a[idParent='"+idMenu+"']").each(function(){
		newHeightSubMenu+=(parseInt($(this).parent().height(),10) + parseInt($(this).parent().css('padding-bottom'),10) + parseInt($(this).parent().css('padding-top'),10));
	});
	
	$(".menu li a[idMenu='"+idMenu+"']").addClass('active');
	$(".menu li a[idParent='"+idMenu+"']").parent().parent().addClass('open');
	$(".menu li a[idParent='"+idMenu+"']").parent().parent().animate({
		height: newHeightSubMenu+'px'
	}, 300, function(){});
	
	if($(".menu li a[idMenu='"+idMenu+"']").parents('ul').length == 2)
	{
		openMenu($(".menu li a[idMenu='"+idMenu+"']").parents('ul:eq(0)').parent().find('a').attr('idMenu'),newHeightSubMenu)
	}	
}

function setDimensionTitleBoutique()
{
	
	
	var fontSize = $("#big_title_store").css('font-size');
	var newFontSize = null;
		
	
	if(parseInt($('#big_title_store').css('height')) > 125 )
	{
		if(widthContentTemplate < (MIN_WIDTH_SECTION + widthMenu))
		{
			newFontSize = parseInt(fontSize) -deltaTitle;
			if(newFontSize < MIN_SIZE_TITLE_BOUTIQUE)
				newFontSize = MIN_SIZE_TITLE_BOUTIQUE;
			$("#big_title_store").css('font-size',newFontSize+'px');
		}
		else if(widthContentTemplate > (MIN_WIDTH_SECTION + widthMenu))
		{
			newFontSize = parseInt(fontSize) +deltaTitle;
			if(newFontSize >= MAX_SIZE_TITLE_BOUTIQUE)
				newFontSize = MAX_SIZE_TITLE_BOUTIQUE;
			$("#big_title_store").css('font-size',newFontSize+'px');
		}
	}
	
}

function setPositionBannerProducts()
{
	var c = 0;
	if(window_width > MIN_WIDTH)
	{
		$('.bannergroup .banneritem').each(function(){
			if(c%2 == 0)
			{
				$(this).css({float: 'left', marginLeft:'+'+(((widthContentTemplate*0.5)-395)*0.5)+'px'});
				
			}
			else
			{
				$(this).css({float: 'right', marginRight:'+'+(((widthContentTemplate*0.5)-395)*0.5)+'px'});
			}
			c++;
		});
	}
	else
	{
		$('.bannergroup .banneritem').each(function(){
			if(c%2 == 0)
			{
				$(this).css({float: 'left', marginLeft:'+0'});
				
			}
			else
			{
				$(this).css({float: 'right', marginRight:'+0'});
			}
			c++;
		});
	}
}

function openDescFibbia(obj)
{
	if(obj.hasClass('open'))
	{	
		obj.css('background-position','0px -6px');
		
		obj.parents('li').find('.description_fibbia').fadeOut();
		obj.parents('li').find('.label_diponibile_fibbie').fadeIn();
		
		obj.parents('li').find('.container_all_fibbie').css('position','absolute').animate({
			top: "0px"
		  }, 500, function(){
			  
			  obj.parents('li').find('.description_fibbia').css('visibility','hidden').css('display','inline');
		});
		
		obj.removeClass('open');
	}
	else
	{
		var nameFibbia = obj.parents('li').find('.nome_fibbia').html();
		dataLayer.push({"buckleName":nameFibbia,"event": "buckle"});
		
		obj.css('background-position','0px -27px');
		obj.parents('li').find('.label_diponibile_fibbie').fadeOut();
		
		var height_description_fibbia = parseInt(obj.parents('li').find('.description_fibbia').height(),10);
		var height_container_all = parseInt(obj.parents('li').find('.container_all_fibbie').height(),10);
		var height_img_fibbia = parseInt(obj.parents('li').find('a').find('img').height(),10);
		
		obj.parents('li').find('.description_fibbia').hide().css('visibility','visible').fadeIn();
		obj.parents('li').find('.container_all_fibbie').css('position','absolute').animate({
			top: "-"+(height_img_fibbia)+"px"
		  }, 500);
		  
		obj.addClass('open');
		
	}
}

function setPositionFooter() {
    $('#footer .content_footer').css({'left': widthMenu+'px', 'width': widthContentTemplate+'px'});
    $('#footer .bt_minimize_footer_home').css({'left': (((widthContentTemplate-$('#footer .bt_minimize_footer_home').width())/2)+widthMenu)+'px'});
}

var elementHeaderCatWatchProcessed = 0;
var heightMaxElementHeaderCatWatchProcessed = 0;
function setDimensionCatWatch(obj)
{
	//console.log("init --- " + heightMaxElementHeaderCatWatchProcessed)
	elementHeaderCatWatchProcessed ++;
	var numElementHeaderCat = $('.element_header_cat').length;
	var heightElementCurrent = 0;

	var numElementForRow = $('.sub_container_element_header_cat_watch').attr('num_element_for_row');
	var widthTotalHeaderCat = parseInt($('.sub_container_element_header_cat_watch').width(),10);
	var widthColumn = widthTotalHeaderCat - 160 / numElementForRow;
	var marginDiference = (160 - (widthTotalHeaderCat - (widthColumn * numElementForRow)))
	var widthWrapElements = (widthColumn * numElementForRow) + marginDiference;


	if(widthWrapElements > widthTotalHeaderCat)
	{
		widthWrapElements = widthTotalHeaderCat;
	}

	var marginImage = parseInt($('.element_header_cat .img_cat').css('margin-left'),10) + parseInt($('.element_header_cat .img_cat').css('margin-right'),10);

	var maxWidthWrapImage = MAX_WIDTH_IMAGE_HEADER_CAT + marginImage;	
	var maxWidthInWrapRow = numElementForRow * maxWidthWrapImage;

	if(widthTotalHeaderCat >= maxWidthInWrapRow)
	{
		$('.wrap_elements_header_cat').width(maxWidthInWrapRow);

		/*
		obj.parents('.element_header_cat').find('.img_cat').width(MAX_WIDTH_IMAGE_HEADER_CAT).height('auto').hide().css('visibility','visible').fadeIn(500, function(){

			heightElementCurrent = parseInt(obj.parents('.element_header_cat').height());
			console.log("HEIGHT:" + obj.parents('.element_header_cat').height());
			if(heightElementCurrent >= heightMaxElementHeaderCatWatchProcessed)
			{
				heightMaxElementHeaderCatWatchProcessed = obj.parents('.element_header_cat').height();
				console.log("entrato 1  ---- " + heightMaxElementHeaderCatWatchProcessed);
			}
			
			//var marginTopCover = (window_height - obj.parents('.element_header_cat').height()) / 2;
			//var heightTitle = $(".block_page h1").height();
			//obj.parents('.wrap_elements_header_cat').css('margin-top',(marginTopCover-heightTitle)+"px");
			

			setScroller();
		});
		*/

		obj.parents('.element_header_cat').find('.img_cat').width(MAX_WIDTH_IMAGE_HEADER_CAT).height('auto').hide().fadeIn(500, function(){

			heightElementCurrent = parseInt(obj.parents('.element_header_cat').height());
			//console.log("HEIGHT:" + obj.parents('.element_header_cat').height());
			if(heightElementCurrent >= heightMaxElementHeaderCatWatchProcessed)
			{
				heightMaxElementHeaderCatWatchProcessed = obj.parents('.element_header_cat').height();
				//console.log("entrato 1  ---- " + heightMaxElementHeaderCatWatchProcessed);
			}

			//console.log(elementHeaderCatWatchProcessed + " --------- " + heightMaxElementHeaderCatWatchProcessed )
			if(elementHeaderCatWatchProcessed == numElementHeaderCat && heightMaxElementHeaderCatWatchProcessed > 0)
			{
				//console.log("AAAAA"+heightMaxElementHeaderCatWatchProcessed);
				
				
				var marginTopCover = (window_height - heightMaxElementHeaderCatWatchProcessed)/2;

				//console.log(marginTopCover);
				

				var heightTitle = $(".block_page h1").height();
				$('.wrap_elements_header_cat').css('margin-top',(marginTopCover-heightTitle-65-20)+"px");
				$('.element_header_cat .img_cat').css('visibility','visible')
				
			}
			else if(heightMaxElementHeaderCatWatchProcessed == 0)
			{
				elementHeaderCatWatchProcessed = 0;
			}
			
			//var marginTopCover = (window_height - obj.parents('.element_header_cat').height()) / 2;
			//var heightTitle = $(".block_page h1").height();
			//obj.parents('.wrap_elements_header_cat').css('margin-top',(marginTopCover-heightTitle)+"px");
			
			setScroller();
		});


	}
	else
	{
		if(widthWrapElements > maxWidthInWrapRow)
			widthColumn = maxWidthWrapImage;
		else
			widthColumn = widthWrapElements / numElementForRow;

		$('.wrap_elements_header_cat').width(widthWrapElements);
		$('.element_header_cat').width(widthColumn);
		var widthImage;
		if(numElementForRow == 2 || numElementForRow == 4)
			widthImage = widthColumn - marginImage;
		else if(numElementForRow == 3)
			widthImage = '100%';

		//obj.parents('.element_header_cat').find('.img_cat').width(widthImage).height('auto').hide().css('visibility','visible').fadeIn(500, function(){setScroller();});
		obj.parents('.element_header_cat').find('.img_cat').width(widthImage).height('auto').hide().fadeIn(500, function(){
			
			heightElementCurrent = parseInt(obj.parents('.element_header_cat').height());
			if(heightElementCurrent >= heightMaxElementHeaderCatWatchProcessed)
			{
				if(heightElementCurrent >= heightMaxElementHeaderCatWatchProcessed)
				{
					heightMaxElementHeaderCatWatchProcessed = obj.parents('.element_header_cat').height();
					//console.log("entrato 1  ---- " + heightMaxElementHeaderCatWatchProcessed);
				}

				//console.log(elementHeaderCatWatchProcessed + " --------- " + heightMaxElementHeaderCatWatchProcessed )
				if(elementHeaderCatWatchProcessed == numElementHeaderCat && heightMaxElementHeaderCatWatchProcessed > 0)
				{
					//console.log("AAAAA"+heightMaxElementHeaderCatWatchProcessed);
					
					
					var marginTopCover = (window_height - heightMaxElementHeaderCatWatchProcessed)/2;

					//console.log(marginTopCover);
					

					var heightTitle = $(".block_page h1").height();
					$('.wrap_elements_header_cat').css('margin-top',(marginTopCover-heightTitle-65-20)+"px");
					$('.element_header_cat .img_cat').css('visibility','visible')
				}
				else if(heightMaxElementHeaderCatWatchProcessed == 0)
				{
					elementHeaderCatWatchProcessed = 0;
				}
					//console.log("entrato 2");
					heightMaxElementHeaderCatWatchProcessed = obj.parents('.element_header_cat').height();
			}

			setScroller();

		});

	}



	
}